5monkeys / django-enumfield

Custom Django field for using enumerations of named constants
MIT License
205 stars 46 forks source link

Import error in Django 4.0 #67

Closed StefanBrand closed 2 years ago

StefanBrand commented 2 years ago
  File "/srv/service/my_project/my_feature/models.py", line 8, in <module>
    from django_enumfield.enum import Enum
  File "/usr/local/lib/python3.9/site-packages/django_enumfield/enum.py", line 15, in <module>
    from django_enumfield.db.fields import EnumField
  File "/usr/local/lib/python3.9/site-packages/django_enumfield/db/fields.py", line 8, in <module>
    from django.utils.encoding import force_text
ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/usr/local/lib/python3.9/site-packages/django/utils/encoding.py)

Features removed in 4.0

CapnKernel commented 2 years ago

I'm also getting this. It seems that force_text has been removed from Django 4.0, and replaced with force_str.

This package also has the same problem:

https://stackoverflow.com/questions/70382084/import-error-force-text-from-django-utils-encoding/70390648

thismatters commented 2 years ago

There is also a similar issue with ugettext.

To mitigate this you can add the following monkeypatch to your settings.py:

import django
from django.utils.encoding import force_str
django.utils.encoding.force_text = force_str
from django.utils.translation import gettext
django.utils.translation.ugettext = gettext
PabloAlexis611 commented 2 years ago

I'm also seeing this error in one of my apps.

Django 4.0 Release Notes say: