fix: add back_populates to SessionHandoff and SessionResolutionOutput relationships

SQLAlchemy SAWarning about overlapping relationships was promoted to
an error by pytest filterwarnings=error, crashing mapper initialization
and causing 500s on every request — cascading to 423+ test failures.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-03-27 17:46:07 +00:00
parent c7abe905f7
commit e130976803
3 changed files with 4 additions and 2 deletions

View File

@@ -253,10 +253,12 @@ class AISession(Base):
)
handoffs: Mapped[list["SessionHandoff"]] = relationship(
"SessionHandoff",
back_populates="session",
cascade="all, delete-orphan",
order_by="SessionHandoff.created_at",
)
resolution_outputs: Mapped[list["SessionResolutionOutput"]] = relationship(
"SessionResolutionOutput",
back_populates="session",
cascade="all, delete-orphan",
)

View File

@@ -44,7 +44,7 @@ class SessionHandoff(Base):
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
# Relationships
session: Mapped["AISession"] = relationship("AISession", foreign_keys=[session_id])
session: Mapped["AISession"] = relationship("AISession", foreign_keys=[session_id], back_populates="handoffs")
handed_off_by_user: Mapped["User"] = relationship("User", foreign_keys=[handed_off_by])
source_branch: Mapped[Optional["SessionBranch"]] = relationship("SessionBranch", foreign_keys=[source_branch_id])
claimed_by_user: Mapped[Optional["User"]] = relationship("User", foreign_keys=[claimed_by])

View File

@@ -36,4 +36,4 @@ class SessionResolutionOutput(Base):
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))
# Relationships
session = relationship("AISession", foreign_keys="SessionResolutionOutput.session_id")
session = relationship("AISession", foreign_keys="SessionResolutionOutput.session_id", back_populates="resolution_outputs")