-
Notifications
You must be signed in to change notification settings - Fork 173
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
fixed isnull, istrue, isfalse lookups/operators #156
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting a PR! I left a few questions below
Any chance you could add some test case/s to assert this change will fix the issue?
advanced_filters/forms.py
Outdated
boolean_lookups = ['isnull', 'istrue', 'isfalse'] | ||
for boolean_lookup in boolean_lookups: | ||
if query_data['field'].endswith(f'__{boolean_lookup}'): | ||
query_data['operator'] = boolean_lookup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems identical to looking up the operator in AdvancedFilterQueryForm.OPERATORS
(as on line 124 below). Could you explain what this does differently, and what scenario this will address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, should be the same. I don't remember the purpose of these lines of mine but I tested it again and it works exactly as your code so we can delete this part. Thanks for double check.
return {formdata['field']: False} | ||
|
||
if formdata['operator'] in ["isnull", "istrue", "isfalse"]: | ||
return {key: True if str(formdata['value']).lower() in ['1', 'true'] else False} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this functionally identical to before, or did something change here? Or is the change that isnull
operator should return {use key: True}
?
From a readability perspective, I think I prefer the previous code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is the most important part. Otherwise it returns 'True'
value (string) instead of True
(boolean), which is incorrect and produces false SQL statement. That's the reason why I iterate only boolean operators ("isnull", "istrue", "isfalse") and not all of the AdvancedFilterQueryForm.OPERATORS
.
Except of that. It allows to combine values like following:
isnull: True
isnull: False
istrue: True
istrue: False
isfalse: True
isfalse: False
which can be useful as well.
@asfaltboy while I understand that tests are important: |
Fixed building query for
isnull
,istrue
andisfalse
lookups as well as initialising form.