-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using AND
(&
) with a predicate that returns None
incorrectly returns True
#165
Comments
Ah, I see you have this note in the README, which I apparently missed:
So I guess this is by design! Conditionals like the one I described above
I'll leave this open for now for any discussion. Thanks again. |
It may be worth at least moving "Skipping predicates" up to the "Combining predicates" portion of the doc so it's more discoverable, since it's important in that context (rather than it being under "Advanced features"). |
I think a truth table for all possible combinations of operations and return values close to the "Combining predicates" section would be very useful. |
Yeah, that could be useful. I also noticed in the "Upgrading from 1.x" section of the docs, it mentions that skipping used to be done with raising a |
I agree it's more "Pythonic" to raise an exception and I have unfortunately no recollection why I made the switch to None. I don't think it's sensible to revert back to the old behaviour as it is a breaking change however I'm willing to be convinced otherwise if others feel the change makes sense. |
When using
&
to combine predicates, if one of the predicates returnsNone
(a falsey value), the overall predicate will mistakenly/confusingly returnTrue
. This is not consistent with running the predicate by itself orOR
ed with other predicates.This behavior can be demonstrated with the following test added to
test_predicates.py
—the final assertion fails:I noticed this in production in my app, where my logic in one predicate was doing
return obj and obj.boolean_field
, expecting that ifobj
wereNone
, it'd still be treated asFalse
in all contexts. It took me a while to figure out what was going on. I didn't feel sure about where/how to fix this indjango-rules
, but hope the above example will help to resolve quickly if possible. Thanks in advance (and thanks for building this great library)!The text was updated successfully, but these errors were encountered: