philipn/django-rest-framework-filters

Fix Deprecation Warnings for v0.10.2

mikelane opened this issue ยท 8 comments

We're on djangorestframework-filters 0.10.2 and we're getting many of these warnings:

...lib/python3.6/site-packages/rest_framework_filters/filterset.py:44: DeprecationWarning: `Filter.name` has been renamed to `Filter.field_name`. See: https://django-filter.readthedocs.io/en/develop/migration.html
    opts.fields = {f.name: f.lookups or []}

Also it happens on line 54 of that same file.

And

.../lib/python3.6/site-packages/rest_framework_filters/filters.py:17: DeprecationWarning: `Filter.name` has been renamed to `Filter.field_name`. See: https://django-filter.readthedocs.io/en/develop/migration.html
    super(AutoFilter, self).__init__(*args, **kwargs)

Thanks. I'll check these out. Any other instances, or just those three?

Also, if you're using Python 3, you might want to check out the djangorestframework-filters 1.0 pre-release. This would also allow you to upgrade to django-filter 2.0

I'll look into the 1.0 pre-release, but we tend to shy away from pre-releases. Those are all the instances I've found so far, but I'm still looking.

I tried upgrading to 1.0.0.dev0 (and django-filters 2.0) but I'm not having success running our code now. Perhaps it's because we're using djangorestframework 3.9? Your readme suggests we need DRF 3.8.

Here is the error I'm getting with 1.0.0.dev0 (sorry, I have to obfuscate a bit of the start of it):

...CommunityFilter(filters.FilterSet):
.venv/lib/python3.6/site-packages/rest_framework_filters/filterset.py:23: in __new__
    new_class = super(FilterSetMetaclass, cls).__new__(cls, name, bases, attrs)
.venv/lib/python3.6/site-packages/django_filters/filterset.py:71: in __new__
    new_class.base_filters = new_class.get_filters()
.venv/lib/python3.6/site-packages/django_filters/filterset.py:326: in get_filters
    fields = cls.get_fields()
.venv/lib/python3.6/site-packages/rest_framework_filters/filterset.py:103: in get_fields
    fields[name] = utils.lookups_for_field(field)
.venv/lib/python3.6/site-packages/rest_framework_filters/utils.py:12: in lookups_for_field
    for expr, lookup in model_field.get_lookups().items():
E   AttributeError: 'NoneType' object has no attribute 'get_lookups'

This happens when I try to import a class with a base class of rest_framework_filters.FilterSet (we have aliased rest_framework_filters to filters on import...

Hm. The error is due to model_field being None, which would imply that the filter's corresponding model field was unresolvable. e.g., it might have been a bad field_name? Not entirely sure. I can't really debug this without seeing some kind of example that demonstrates the error.

Either way, it's up to you if you want to upgrade and try to debug this. Otherwise, I plan on fixing the warnings and cutting a 0.10.3 release.

Okay - I've just uploaded v0.11.0 to PyPI. This version specifically support django-filter v1.1, but not v1.0. Keeping this open as a reminder to update master with the v0.11 changelog.

Update the master branch w/ changelogs

Thanks bunches. My DeprecationWarnings went from 5112 before this change to 433 ๐Ÿ˜†