Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Fix FilterSet proxy#4620
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Fix FilterSet proxy#4620
Uh oh!
There was an error while loading.Please reload this page.
Conversation
lovelydinosaur left a comment
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.
Great work on resolving this! One minor proposed change as above - let us know if you think the proposal doesn't make sense in some way, but otherwise I think it's worth us making sure that we're able to give friendly error messages in the case thedjango-filter isn't installed.
rest_framework/filters.py Outdated
| returnsuper(FilterSetMetaclass,cls).__new__(cls,name,bases,attrs) | ||
| classFilterSet(six.with_metaclass(FilterSetMetaclass,DFFilterSet)): | ||
| pass |
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.
For user-friendlyness we should also have a branch that includes the case where django_filters isn't is installed so thatFilterSet imports still succeed, but raise an assertion error letting the user know that they need to installdjango-filter.
lovelydinosaurOct 24, 2016 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 could just be...
if django_filters: ...else: def FilterSet(*args, **kwargs): assert False, 'django-filter must be installed to use the `FilterSet` class'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.
Makes sense. I've added a commit for this. It's a bit complicated since FilterSet is designed to be subclassed, so getting a nice error message at the point of use needed another metaclass.
| ifbases!= (object,): | ||
| assertFalse,'django-filter must be installed to use the `FilterSet` class' | ||
| super(FilterSetMetaclass,self).__init__(name,bases,attrs) | ||
| _BaseFilterSet=object |
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.
Wondering if it'd be marginally cleaner to haveFilterSet declarationinside theif case, rather thanafter it.
Then theelse case could just have aFilterSet stub that raises an assertion error, rather than having aFilterSet metaclass.
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.
The metaclass is required if we want the assert to fire whenFilterSet is subclassed. That way the context of the error is at the actual point of use. Another alternative is a dummy class with an assert in__init__, but then the error won't happen until you hit the view.
lovelydinosaur commentedOct 26, 2016
Reckon we're good to go with this. Anyone else want to chime in? |
spearki commentedOct 26, 2016
So for the coverage stuff. How do you feel about adding a new tox env |
lovelydinosaur commentedNov 1, 2016
I don't understand what that'd change / resolve. I think we just want to turn off or dial down the coverage tests at some point. It's useful to see the changes, but I don't really want it passing or failing a pull request. |
lovelydinosaur commentedNov 1, 2016
Great stuff, thanks for your work on this! |
Description
Fix FilterSet proxying to be aware of parent metaclasses.
Closes#4619.