- edited description
WHERE 0 = 1 silently generated
Issue #3033
invalid
Running:
query = session.query(A).filter( and_( A.id == string_a, A.b.key == string_b ) )
where:
class A(Base):
__tablename__ = 'a_table'
id = Column(Integer, primary_key = True)
# ...
class B(Base):
__tablename__ = 'b_table'
id = Column(Integer, primary_key = True)
key = Column(String(36), nullable = False)
# ...
a_id = Column(Integer, ForeignKey('a_table.id'), nullable = False)
a = relationship("A", backref = backref("b", uselist = False))
produces a query like:
SELECT ...
FROM a_table
WHERE 0 = 1
Comments (6)
-
reporter -
reporter - edited description
-
repo owner The "A.b.key" use here is invalid. You mean to say this:
session.query(A).join(A.b).filter(A.id == "x").filter(B.key == "y")
-
repo owner the query as you have it is essentially this:
session.query(A).filter(A.b.key == "x")
which is:
session.query(A).filter("b" == "x")
which is:
session.query(A).filter(False)
hence 1 == 0. SQLAlchemy is working correctly.
-
repo owner - changed status to invalid
this is a usage error.
-
reporter Thanks.
- Log in to comment