fix: eager-load server defaults on StorageObjects to avoid MissingGreenlet

publish_version -> create_server_object_payload -> storage_payload reads
item.created_at on a sync helper. Without eager_defaults, server-default
columns stay unloaded after INSERT, the next sync read triggers a lazy
refresh through the async driver, and MissingGreenlet fires.

Enable mapper-level eager_defaults on StorageObjects so server-default
columns (created_at, updated_at, ...) are round-tripped into the ORM
object immediately after INSERT. No other table or session config
touched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-08-05 18:36:26 +08:00
co-authored by Claude Fable 5
parent 78c3f1e954
commit d5de1a63d4
+7
View File
@@ -10,6 +10,13 @@ from common.db.base import Base
class StorageObjects(Base): class StorageObjects(Base):
__tablename__ = "storage_objects" __tablename__ = "storage_objects"
# Force SQLAlchemy to round-trip server-default columns (created_at,
# updated_at, ...) via a follow-up SELECT after INSERT. Without this,
# attributes populated by `server_default` stay unloaded on the ORM
# object and the next sync read (e.g. storage_payload in storage_api.py)
# triggers a lazy refresh through the async driver, which raises
# MissingGreenlet because the read happens outside an awaitable.
__mapper_args__ = {"eager_defaults": "auto"}
__table_args__ = ( __table_args__ = (
Index("fk_storage_created_by", "created_by"), Index("fk_storage_created_by", "created_by"),
Index("idx_storage_content_hash", "content_hash"), Index("idx_storage_content_hash", "content_hash"),