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 #35173 -- Reallowed filtering with __isnull on foreign keys not listed in list_filters. #17844
Conversation
111ffff
to
6fd450b
Compare
Hello @Hisham-Pak, thank you for this pull request. I don't think this is the right approach: as far as I see this branch is just restoring the whole Ideally, the fix would only enlarge/modify the current Does this make sense? cc/ @sarahboyce |
Hi @nessita, thanks for the review. Currently I was not able to find a way to combine these checks in one
Will update this if I found a way around. And yes I think |
Thank you for the response. If the |
6fd450b
to
6245b88
Compare
@nessita, I implemented the changes you suggested. Let me know if it looks good. |
28ef15e
to
d699eda
Compare
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.
Thank you for working on this @Hisham-Pak
django/contrib/admin/options.py
Outdated
model._meta.auto_field is None | ||
or part not in getattr(prev_field, "to_fields", []) | ||
) | ||
and (field.is_relation or not getattr(field, "primary_key", None)) |
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.
I have a question about this: the not getattr(field, "primary_key", None)
, what is it covering exactly? is it asking for whether there is primary_key field? or if the primaty_key field is None? what happens if the value of primary_key
is falsy?
I change the code to be:
and (field.is_relation or not getattr(field, "primary_key", None)) | |
and (field.is_relation or not field.primary_key) |
and no test fails, so I think that we can either simplify the code or add tests ensuring the have the more robust guard here.
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.
not getattr(field, "primary_key", None)
was checking for not(hasattr(field, "primary_key") and field.primary_key)
. But I think this was not necessary as all fields inherit from Field
class which already has primary_key
attribute. The only exception I can think is of reverse relations and for that field.is_relation
is already set to True.
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 @Hisham-Pak, would you have time to extend the test case or add a new one with such case so we evaluate if we need to further tweak the if
guard?
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.
I don't think we need any further tweaking. It already is looking good.
…ign keys when not included in ModelAdmin.list_filters. Regression in f80669d. Thanks Sarah Boyce for the review.
6dc6116
to
ebbab6f
Compare
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.
Thank you @Hisham-Pak! I made small changes and tweaked the release notes.
Ticket: https://code.djangoproject.com/ticket/35173