or_ and and_() should emit a warning / someday raise an error with no arguments
See original GitHub issueThis 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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (18 by maintainers)
Top Results From Across the Web
Raise warning in Python without interrupting program
I use the following simple function to check if the user passed a non-zero number to it. If so, the program should warn...
Read more >8. Errors and Exceptions — Python 3.11.1 documentation
Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs....
Read more >How to Throw Exceptions in Python - Rollbar
This article will show you how to raise exceptions in your Python code and how to address exceptions. Difference Between Python Syntax Errors...
Read more >Error Codes | Yarn - Package Manager
A list of Yarn's error codes with detailed explanations.
Read more >Documentation: 15: 43.9. Errors and Messages - PostgreSQL
The last variant of RAISE has no parameters at all. This form can only be used inside a BEGIN block's EXCEPTION clause; it...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll update the warning and make the changes to the test.
Maybe this guidance should also be in the documentation for
and_
andor_
?Federico Caselli has proposed a fix for this issue in the master branch:
Deprecate empty or_() and and_() https://gerrit.sqlalchemy.org/1682