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

Improve exception message for invalid filter result #943

Merged
merged 2 commits into from
Jul 13, 2018

Conversation

rpkilby
Copy link
Collaborator

@rpkilby rpkilby commented Jul 13, 2018

As mentioned in #938, the exception for an invalid filter result isn't that helpful. e.g., if a custom filter method unintentionally returns a None value, you end up with NoneType has no attribute filter, which lacks any context about the offending FilterSet and Filter instance.

@jpic - would this exception have been helpful the first time around? e.g.

Expected 'F.invalid' to return a QuerySet, but got a NoneType instead.

Ryan P Kilby added 2 commits July 12, 2018 21:59
The current exception is an AttributeError that lacks any context about
the filter call. e.g., "NoneType has no attribute filter". This message
is improved by including which filterset and which filter are incorrect.
@codecov-io
Copy link

codecov-io commented Jul 13, 2018

Codecov Report

Merging #943 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #943      +/-   ##
==========================================
+ Coverage   97.95%   98.04%   +0.09%     
==========================================
  Files          15       15              
  Lines        1122     1123       +1     
==========================================
+ Hits         1099     1101       +2     
+ Misses         23       22       -1
Impacted Files Coverage Δ
django_filters/filterset.py 100% <100%> (ø) ⬆️
django_filters/filters.py 98.74% <0%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1f1c65...cd81823. Read the comment docs.

@jpic
Copy link

jpic commented Jul 13, 2018

LGTM

@carltongibson carltongibson added this to the Version 2.0 milestone Jul 13, 2018
@carltongibson carltongibson merged commit 82a47fb into carltongibson:master Jul 13, 2018
@rpkilby rpkilby deleted the filter-results-error branch July 13, 2018 13:16
@stefanw
Copy link

stefanw commented Oct 10, 2018

I would like to use django-filter for things besides Django's querysets like Haystack's SearchQuerySet. The assertion in this PR with an isinstance (not even issubclass) is a bit too assuming. Maybe a None check would suffice to report a common error?

@rpkilby
Copy link
Collaborator Author

rpkilby commented Oct 10, 2018

Hi @stefanw. django-filter isn't going to be compatible with SearchQuerySet since a SQS is not compatible with the standard QuerySet API. They have similarities, but they are not compatible with each other. e.g., you cannot combine a SearchQuerySet with a standard QuerySet via & or |, SearchQuerySet cannot accept Q objects, etc...

The filter_queryset method is functionally 3 lines of code. If you want django-haystack compatibility, I would recommend creating a custom base filterset class that overrides this method.

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.

5 participants