jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting

Home Page:https://django-polymorphic.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error at startup with Django 5 + Python 3.11 + django-polymorphic==3.1.0

Djailla opened this issue · comments

Hello

I have a weird error with my project (a big Django project) with such error message at startup:

± ./manage.py runserver

0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Watching for file changes with StatReloader
2024-02-29 19:51:37,698:INFO:django.utils.autoreload:668:Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    autoreload.raise_last_exception()
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/core/management/__init__.py", line 394, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
    app_config.ready()
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/contrib/admin/apps.py", line 27, in ready
    self.module.autodiscover()
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/contrib/admin/__init__.py", line 52, in autodiscover
    autodiscover_modules("admin", register_to=site)
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules
    import_module("%s.%s" % (app_config.name, module_to_search))
  File "/opt/homebrew/Cellar/python@3.11/3.11.8/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/polymorphic/admin/__init__.py", line 7, in <module>
    from .childadmin import PolymorphicChildModelAdmin
  File "/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/polymorphic/admin/childadmin.py", line 11, in <module>
    from ..admin import PolymorphicParentModelAdmin
ImportError: cannot import name 'PolymorphicParentModelAdmin' from partially initialized module 'polymorphic.admin' (most likely due to a circular import) (/Users/b.vallet/Workspace/rackguru/api/.venv11/lib/python3.11/site-packages/polymorphic/admin/__init__.py)

Here is the order of INSTALLED_APPS

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.humanize",
    "django.contrib.messages",
    "django.contrib.sessions",
    "whitenoise.runserver_nostatic",
    "django.contrib.staticfiles",
    "django_countries",
    "django_extensions",
    "django_markup",
    "django_prometheus",
    "django_q",
    "django_tables2",
    "django_bootstrap5",
    "corsheaders",
    "polymorphic",
    "rackguru.api",
    "rackguru.bundle",

Do you have an idea about what is broken ?

Thanks a lot

Cloud you please double check that is not an issue on your side? Was the app working before? Did you recently update to version 3.1?

Version 3.1 has been out for a while now, so I don't think there would be a problem with the package.

Thanks!

Works perfect with Django 4.2

My point is that I have no clue where to look for to try to debug. If you have any idea ?

Okay, this seems to be an issue with Django 5.0? Let me look and see if I can reproduce your issue.

Here is also an idea. Create a separate django project. Install django-polymorphic and see if you get the same error.

Cannot reproduce with requirements up to date. I will close this issue