django / django-localflavor

Country-specific Django helpers, formerly of contrib fame
https://django-localflavor.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
812 stars 289 forks source link

Upgrade to Django 4.0 #474

Closed smcalilly closed 1 year ago

smcalilly commented 1 year ago

I'm wanting to use this package in an app with Django 4.0.7, but I get this error whenever I try to build the app:

  File "/code/manage.py", line 22, in <module>
    main()
  File "/code/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
    django.setup()
  File "/usr/local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/code/accounts/models.py", line 5, in <module>
    from localflavor.us.models import USStateField, USZipCodeField
  File "/usr/local/lib/python3.10/site-packages/localflavor/us/models.py", line 2, in <module>
    from django.utils.translation import ugettext_lazy as _
ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/usr/local/lib/python3.10/site-packages/django/utils/translation/__init__.py)
------

It appears that this is a breaking change with the latest Django version, based on this: https://forum.djangoproject.com/t/importerror-cannot-import-name-ugettext-lazy-from-django-utils-translation/10943/10

Would it be alright if I submitted a patch PR that upgrades to Django 4.0? (I've never contributed to an open source project so I'm not sure how this works...)

claudep commented 1 year ago

You are probably using an old version of localflavor. the ugettext_lazy call provoking the error was updated 3 years ago. The current code is already compatible with Django 4.0.

smcalilly commented 1 year ago

@claudep ah you're right. thanks for pointing that.

perhaps updating the readme would be helpful to indicate that the current code is already compatible with django 4.0 since it's not there and misleading without it.

claudep commented 1 year ago

Sure, and that could also be done in a patch adding/verifying support for Django 4.1.