-
-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Relationships with complex join conditions don't seem to be loaded correctly
Describe the Bug
I have a SqlAlchemy data model like below
class Point(Base):
id: Mapped[UUID]
name: Mapped[str]
lines: Mapped[list[Line]] = relationship(
primaryjoin="or_(Line.point1_id == Point.id, Line.point2_id == Point.id)",
)
class Line(Base):
id: Mapped[UUID]
point1_id: Mapped[UUID] = mapped_column(ForeignKey("point.id"))
point2_id: Mapped[UUID] = mapped_column(ForeignKey("point.id"))
point1: Mapped[Point] = relationship(foreign_keys=[point1_id])
point2: Mapped[Point] = relationship(foreign_keys=[point2_id])
points: Mapped[list[Point]] = relationship(
back_populates="lines",
primaryjoin="or_(Line.point1_id == point.id, Line.point2_id == point.id)",
overlaps="point1,point2",
uselist=True,
)
A GraphQL query like below seems to load a line successfully, and loads point1 and point2 data, but returns an empty list for "points", even though point1 and point2 are defined.
loadLine(id) {
name
point1 {
name
}
point2 {
name
}
points {
edges {
node {
name
}
}
}
}
I've confirmed that the SqlAlchemy relationship line.points
correctly loads a list of points in other contexts.
I see that strawberry-sqlalchemy is generating sql queries like below, which will always be false if point1_id != point2_id
SELECT ...
FROM point
WHERE (point.id, point.id) IN ((<point1_id>, <point2_id>))
System Information
- Operating system: Mac 15.3
- Versions
strawberry-graphql = {extras = ["fastapi"], version = "^0.260.2"}
sqlalchemy = "^2.0.40"
psycopg = {extras = ["binary"], version = "^3.2.7"}
strawberry-sqlalchemy-mapper = "0.6.2"
Additional Context
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working