stephenmcd / filebrowser-safe

File manager for Mezzanine
Other
42 stars 104 forks source link

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. when adding a featured image using EXTRA_MODELS_FIELDS #143

Open wimfeijen opened 1 year ago

wimfeijen commented 1 year ago

Using EXTRA_MODEL_FIELDS = ( ( "mezzanine.pages.models.RichTextPage.featured_image", "mezzanine.core.fields.FileField", ("featured image",), { "blank": True, "null": True, "upload_to": "afbeeldingen", "format": "Image", "max_length": 255, }, ), ) gives us an error, see traceback below.

We are using: filebrowser-safe==1.1.1 Mezzanine==6.0.0

Traceback (most recent call last): File "/home/django/projects/veiligpracticum/manage.py", line 16, in execute_from_command_line(sys.argv) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/core/management/init.py", line 419, in execute_from_command_line utility.execute() File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/core/management/init.py", line 395, in execute django.setup() File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/apps/config.py", line 224, in create import_module(entry) File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/boot/init.py", line 76, in fields = parse_extra_model_fields(getattr(settings, "EXTRA_MODEL_FIELDS", [])) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/boot/init.py", line 63, in parse_extra_model_fields field_class = import_field(entry[1]) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/boot/init.py", line 44, in import_field return import_dotted_path(fully_qualified) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/utils/importing.py", line 21, in import_dotted_path module = import_module(module_path) File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/core/fields.py", line 104, in FileBrowseField = import_dotted_path( File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/utils/importing.py", line 21, in import_dotted_path module = import_module(module_path) File "/usr/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 790, in exec_module File "", line 228, in _call_with_frames_removed File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/filebrowser_safe/fields.py", line 15, in from filebrowser_safe.base import FieldFileObject File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/filebrowser_safe/base.py", line 12, in from filebrowser_safe.functions import get_directory, get_file_type, path_strip File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/filebrowser_safe/functions.py", line 13, in from mezzanine.utils.sites import current_site_id File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/mezzanine/utils/sites.py", line 6, in from django.contrib.sites.models import Site File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/contrib/sites/models.py", line 78, in class Site(models.Model): File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/db/models/base.py", line 108, in new app_config = apps.get_containing_app_config(module) File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/apps/registry.py", line 253, in get_containing_app_config self.check_apps_ready() File "/var/virtualenvs/veiligpracticum/lib/python3.9/site-packages/django/apps/registry.py", line 136, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

wimfeijen commented 1 year ago

In /filebrowser_safe/functions.py, the changes below seem to solve this:

from django.core.exceptions import AppRegistryNotReady

try: from mezzanine.utils.sites import current_site_id except AppRegistryNotReady: