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

Fix filtering with GlobalIDFilter #977

Merged
merged 1 commit into from Jun 25, 2020

Conversation

hubertsiuzdak
Copy link
Contributor

resolves #808, resolves #542

Filtering with not valid global ID doesn't raise any exception, and the query set without filter applied is returned instead. That happens due to the fact that django-filter no longer performs error handling itself (see carltongibson/django-filter#1078). This PR solves the issue by validating the filterset in DjangoFilterConnectionField.

Copy link
Member

@jkimbo jkimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good change but the tests are failing @hubertsiuzdak

Comment on lines 69 to 70
else:
raise ValidationError(json.dumps(filterset.errors.get_json_data()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else:
raise ValidationError(json.dumps(filterset.errors.get_json_data()))
raise ValidationError(json.dumps(filterset.errors.get_json_data()))

No need for the else statement.

@hubertsiuzdak hubertsiuzdak force-pushed the master branch 2 times, most recently from 51d2020 to 434a776 Compare June 7, 2020 23:16
Comment on lines +66 to +68
if filterset.form.is_valid():
return filterset.qs
raise ValidationError(filterset.form.errors.as_json())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support Python 2.7 and django-filter 1.1 that form property is needed. In Graphene-Django v3 we use django-filter 2.x which allows to call is_valid and errors directly on filterset instances. We may want to refactor that for v3 as it slightly improves readability.

@hubertsiuzdak hubertsiuzdak requested a review from jkimbo June 7, 2020 23:59
Copy link
Collaborator

@zbyte64 zbyte64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

@hubertsiuzdak
Copy link
Contributor Author

@jkimbo Can you take a look again?

@jkimbo
Copy link
Member

jkimbo commented Jun 25, 2020

Thanks @hubertsiuzdak

@jkimbo jkimbo merged commit 3c6733e into graphql-python:master Jun 25, 2020
@jkimbo
Copy link
Member

jkimbo commented Jun 25, 2020

Released in v2.11.0

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.

Using exact filter on Relay with ForeignKey model Can't use GlobalIDFilter as FilterSet field
3 participants