Fix SpecVersion/ProcessingJob circular relationship direction error

Remove bidirectional back_populates between SpecVersion and ProcessingJob
since both sides have FKs to each other (circular), causing SQLAlchemy to
see both as MANYTOONE. ProcessingJob.spec_version is now a standalone
relationship with explicit foreign_keys. SpecVersion no longer has a
reverse relationship to ProcessingJob (not needed for any queries).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
michael 2026-02-12 15:42:35 -06:00
parent 4833fa127d
commit 1601622e07

View file

@ -250,10 +250,6 @@ class SpecVersion(Base):
# Relationships
knowledge_base: Mapped["KnowledgeBase"] = relationship("KnowledgeBase", back_populates="spec_versions")
processing_job: Mapped[Optional["ProcessingJob"]] = relationship(
"ProcessingJob", back_populates="spec_version",
foreign_keys="[SpecVersion.processing_job_id]",
)
__table_args__ = (
UniqueConstraint("knowledge_base_id", "version_number", name="uq_kb_version_number"),
@ -283,6 +279,6 @@ class ProcessingJob(Base):
# Relationships
knowledge_base: Mapped["KnowledgeBase"] = relationship("KnowledgeBase", back_populates="processing_jobs")
spec_version: Mapped[Optional["SpecVersion"]] = relationship(
"SpecVersion", back_populates="processing_job",
foreign_keys="[ProcessingJob.spec_version_id]",
"SpecVersion",
foreign_keys=[spec_version_id],
)