From 1601622e079f9265c49bb0574ff951559cc3a463 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 12 Feb 2026 15:42:35 -0600 Subject: [PATCH] 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 --- backend/app/models/models.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/app/models/models.py b/backend/app/models/models.py index 1fbb670..ded4770 100755 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -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], )