deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.37k stars 258 forks source link

AttributeError: 'str' object has no attribute 'mro' #721

Closed NikGor closed 7 months ago

NikGor commented 7 months ago

Hello,

I've encountered an issue with django-modeltranslation in my Django projects, which leads to an AttributeError when I add 'modeltranslation' to my INSTALLED_APPS in settings.py. The error message is as follows:

AttributeError: 'str' object has no attribute 'mro'

This error is triggered during the Django development server startup and seems to be related to the model loading process. The traceback points to an interaction with cuser.middleware.CuserMiddleware, although cuser is not directly used or mentioned in my INSTALLED_APPS or MIDDLEWARE.

Environment:

Steps to Reproduce:

  1. Add 'modeltranslation' to INSTALLED_APPS in settings.py.
  2. Start the Django development server with python manage.py runserver.
  3. The error occurs during the server startup.

What I've Checked:

I'm unsure why django-modeltranslation's integration would affect or trigger an error related to cuser, especially since cuser is not a direct dependency in my project. I suspect there might be an indirect interaction or conflict happening when models are loaded or translated by django-modeltranslation.

Could you please provide any insights or suggestions on how to resolve this issue? Is there a known compatibility issue with Django, cuser or a specific configuration required to avoid such conflicts?

Thank you for your assistance.


 Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/niko/.local/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/niko/.local/lib/python3.10/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "/home/niko/.local/lib/python3.10/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/home/niko/.local/lib/python3.10/site-packages/django/core/management/__init__.py", line 394, in execute
    autoreload.check_errors(django.setup)()
  File "/home/niko/.local/lib/python3.10/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/home/niko/.local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/niko/.local/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/home/niko/.local/lib/python3.10/site-packages/django/apps/config.py", line 269, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/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 "/home/niko/.local/lib/python3.10/site-packages/modeltranslation/models.py", line 31, in <module>
    from cuser.middleware import CuserMiddleware
  File "/home/niko/.local/lib/python3.10/site-packages/cuser/middleware.py", line 3, in <module>
    from cuser.compat import User
  File "/home/niko/.local/lib/python3.10/site-packages/cuser/compat.py", line 15, in <module>
    User = lazy(get_user_model, AUTH_USER_MODEL)
  File "/home/niko/.local/lib/python3.10/site-packages/django/utils/functional.py", line 175, in lazy
    for type_ in resultclass.mro():
AttributeError: 'str' object has no attribute 'mro'
remithomasadaptive commented 3 months ago

@NikGor How did you fix this issue ?

TzuChuanWang commented 2 months ago

@remithomasadaptive @NikGor How did you fix this issue ?