From 4833fa127d91849a1ba7abe128f064bf46af76fe Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 12 Feb 2026 15:40:36 -0600 Subject: [PATCH] Fix SQLAlchemy ambiguous FK error between SpecVersion and ProcessingJob Add explicit foreign_keys argument to both sides of the bidirectional relationship to resolve the multiple FK paths (SpecVersion.processing_job_id and ProcessingJob.spec_version_id). Co-Authored-By: Claude Opus 4.6 --- backend/app/models/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/app/models/models.py b/backend/app/models/models.py index 3658436..1fbb670 100755 --- a/backend/app/models/models.py +++ b/backend/app/models/models.py @@ -250,7 +250,10 @@ 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") + 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"), @@ -279,4 +282,7 @@ 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") + spec_version: Mapped[Optional["SpecVersion"]] = relationship( + "SpecVersion", back_populates="processing_job", + foreign_keys="[ProcessingJob.spec_version_id]", + )