philipn/django-rest-framework-filters

ImportError: cannot import name 'six'

ibayeux opened this issue · 18 comments

A specified in Django 3.0 release note, django.utils.six is removed. In case you need it, it is advised to use pypi packages instead.
can you update?

"pip install --upgrade djangorestframework"
update the Django rest framework to the latest will resolve the issue.

Same happening here, upgrading djangorestframework didn't help

Same happening here, upgrading djangorestframework didn't help

Which Django version you are using currently?

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

Having the same import problem. I tried your solution and it worked but do u know how stable it is for production?

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

Having the same import problem. I tried your solution and it worked but do u know how stable it is for production?

Unfortunately, I have no clear idea about that. I'm writing for tools for my personal use only. However, I'd suppose that a production-ready version won't be released with a dev label on it :)

getting this error after placing configuration dict.

'DEFAULT_FILTER_BACKENDS': (
'rest_framework_filters.backends.RestFrameworkFilterBackend',
),

Django version: 3.0.7
ImportError: Could not import 'rest_framework_filters.backends.RestFrameworkFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. ImportError: cannot import name 'six' from 'django.utils'

gmuj commented

I solved this by installing latest https://github.com/carltongibson/django-filter
Since most of the stuff used by this library is merged back into django-filter I didn't have any problems using it. You just need to follow the installation step and change package imports paths.

Note that you need to uninstall this package before as it relies on an older version and you get this error
ERROR: djangorestframework-filters 0.11.1 has requirement django-filter~=1.1, but you'll have django-filter 2.3.0 which is incompatible.

Hey @poojansmobio do you have any updates on this? I'm happy to collaborate with you to solve this issue!

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

I did it but I get a dependency issue:

djangorestframework-jsonapi 3.2.0 requires djangorestframework<3.12,>=3.10, but you'll have djangorestframework 3.12.1 which is incompatible.

So basically I need to wait for a new version of djangorestframework-jsonapi before I can do this update.

Hey, @petrosschilling updating the django-rest-framework and installing pip install six worked for me.

I did it but I get a dependency issue:

djangorestframework-jsonapi 3.2.0 requires djangorestframework<3.12,>=3.10, but you'll have djangorestframework 3.12.1 which is incompatible.

So basically I need to wait for a new version of djangorestframework-jsonapi before I can do this update.

In your case try downgrading it to djangorestframework==3.11.0 and check.

I'm using JRF 3.11.1. Which save me from the conflicts.

The problem lies in the filterset.py file.

I checked the tag of version 0.11.1 and it still uses six.

filterset.py

from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
import copy

from django.db.models.constants import LOOKUP_SEP
from django.utils import six

from django_filters import filterset, rest_framework
from django_filters.utils import get_model_field

from . import filters
from . import utils

I'm using JRF 3.11.1. Which save me from the conflicts.

The problem lies in the filterset.py file.

I checked the tag of version 0.11.1 and it still uses six.

filterset.py

from __future__ import absolute_import
from __future__ import unicode_literals

from collections import OrderedDict
import copy

from django.db.models.constants import LOOKUP_SEP
from django.utils import six

from django_filters import filterset, rest_framework
from django_filters.utils import get_model_field

from . import filters
from . import utils

Replace
from django.utils import six
To
import six

Replace
from django.utils import six
To
import six

Well that is not feasible, because in case i need to re-create my environment I will have to remember to change that import. Not only me but all other devs as well.

What I've done (for now) is to use the latest dev version (djangorestframework-filters==1.0.0.dev2) which will do for the time being.

The RelatedFilter is pretty good by the way. It is exactly what I was looking for. It doesn't pick up the override of the lookup_expr though:

class ClientAccountFilterSet(BaseFilterSet):
    individuals = RelatedMultipleFilter(IndividualFilterSet, queryset=Individual.objects.all())

class IndividualFilterSet(BaseFilterSet):
    first_name = CharFilter(lookup_expr="icontains")

    class Meta:
        model = Individual
        fields = [
            "first_name",
        ]

It still filter with exact not with icontains.

But that is another issue.

Thanks for your time and help!
I might look into fixing this problem :)

ModuleNotFoundError: No module named 'rest_framework_filtersstorages'

After trying

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

ModuleNotFoundError: No module named 'rest_framework_filtersstorages'

After trying

Updating to djangorestframework-filters==1.0.0.dev0 resolved my same issue.

You might have missed a comma (,) after 'rest_framework_filter'

@ashish141199 The latest pre-release is 1.0.0.dev2