basxsoftwareassociation / bread

Engine to create database applications based on Django and the IBM Carbon Design System
BSD 3-Clause "New" or "Revised" License
19 stars 2 forks source link

Django4: cannot import name 'LANGUAGE_SESSION_KEY' from 'django.utils.translation' #121

Closed tpokorra closed 2 years ago

tpokorra commented 2 years ago

I got this error now on make runserver:

(.venv) [timotheus@laptoptphp820G3 basxconnect_demo]$ make runserver
. .venv/bin/activate && python manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified some issues:

WARNINGS:
dynamic_preferences.GlobalPreferenceModel: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the DynamicPreferencesConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
dynamic_preferences_users.UserPreferenceModel: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the UserPreferencesConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
exchange.Rate: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
    HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.

System check identified 3 issues (0 silenced).
January 15, 2022 - 06:36:37
Django version 4.0.1, using settings 'basxconnect_demo.settings.dev'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/servers/basehttp.py", line 46, in get_internal_wsgi_application
    return import_string(app_path)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
    import_module(module_path)
  File "/usr/lib64/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 "/home/timotheus/dev/basx/basxconnect_demo/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
    self.load_middleware()
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/handlers/base.py", line 40, in load_middleware
    middleware = import_string(middleware_path)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/module_loading.py", line 15, in cached_import
    import_module(module_path)
  File "/usr/lib64/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 "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/bread/middleware.py", line 12, in <module>
    from django.utils.translation import LANGUAGE_SESSION_KEY, activate, get_language
ImportError: cannot import name 'LANGUAGE_SESSION_KEY' from 'django.utils.translation' (/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/translation/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib64/python3.10/threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.10/threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/management/commands/runserver.py", line 144, in inner_run
    handler = self.get_handler(*args, **options)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/management/commands/runserver.py", line 70, in get_handler
    return get_internal_wsgi_application()
  File "/home/timotheus/dev/basx/basxconnect_demo/.venv/lib64/python3.10/site-packages/django/core/servers/basehttp.py", line 48, in get_internal_wsgi_application
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'wsgi.application' could not be loaded; Error importing module.
tpokorra commented 2 years ago

this is related to https://github.com/basxsoftwareassociation/bread/commit/276550732fda1673c70242f179f06a299491a271#diff-7f3098159a9cbe14418d1c63fdc9bcf0dd75fcbddcbf02d0f80034781c247c0b

tpokorra commented 2 years ago

other projects have had this issue too: https://github.com/django/channels/issues/1609

tpokorra commented 2 years ago

I wonder if we can require Django 3 for bread, and avoid Django 4 until we fixed all issues and tested it properly?

see https://stackoverflow.com/a/8161816/1632368 https://github.com/basxsoftwareassociation/bread/blob/main/setup.py#L30 "Django~=3",

saemideluxe commented 2 years ago

Well, I would like to be ready for 4.0 as soon as possible, so I will fix this one very soon.

This is related to a change in Django 4.0, see https://github.com/django/django/commit/d134b0b93ee10a2128c595997cbc6022c4a982f7 Because we never call set_language the deprecation warning does not show up. This was a suboptimal implementation anyway as it seems we relied on internals.

Thanks for reporting this.

saemideluxe commented 2 years ago

Okay, I pushed a fix to main, new version should be released on pip in a few minutes.