sqlalchemy: or_ and and_() should emit a warning / someday raise an error with no arguments

This is using SQLAlchemy-1.3.12.

I would expect or_() to produce kind of false, but it has truthy behaviour. Note, false is neutral element for disjunction (and true for conjunction), so I would expect adding false() to it didn’t change result, that’s why I would expect following statements producing the same result:

print(session.query(literal(42)).filter(or_()).first())
# (42,)
print(session.query(literal(42)).filter(or_(false())).first())
# None

Note, that for and_ everything works as expected:

print(session.query(literal(42)).filter(and_()).first())
# (42,)
print(session.query(literal(42)).filter(and_(true())).first())
# (42,)

There might some rationale behind current behaviour I am missing.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (18 by maintainers)

Most upvoted comments

I’ll update the warning and make the changes to the test.

Maybe this guidance should also be in the documentation for and_ and or_?