Skip to content
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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

eriktelepovsky
Copy link

Fixed building query for isnull, istrue and isfalse lookups as well as initialising form.

Copy link
Member

@asfaltboy asfaltboy left a 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?

boolean_lookups = ['isnull', 'istrue', 'isfalse']
for boolean_lookup in boolean_lookups:
if query_data['field'].endswith(f'__{boolean_lookup}'):
query_data['operator'] = boolean_lookup
Copy link
Member

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?

Copy link
Author

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}
Copy link
Member

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

Copy link
Author

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.

@slorg1
Copy link

slorg1 commented Aug 2, 2022

@asfaltboy while I understand that tests are important:
Can we get this approved? The tool is losing a lot of functionality by not having this issue addressed.
Thx!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants