question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
CaselITcommented, Dec 29, 2019

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_?

0reactions
sqla-testercommented, Jan 25, 2020

Federico Caselli has proposed a fix for this issue in the master branch:

Deprecate empty or_() and and_() https://gerrit.sqlalchemy.org/1682

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found