Integrating django-music-publisher==21.5.1 into django-oscar 3.1 app throws a "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

28 views
Skip to first unread message

Wale Opakunle

unread,
Sep 1, 2021, 10:32:48 AM9/1/21
to django-oscar

Hello,

I am attempting to add a third party application (django-music-publisher) into my existing Django Oscar 3.1 applications following the instructions here in the django music publisher documentation.

 

My current Oscar setup works but as soon as I add ‘music_publisher.apps.MusicPublisherConfig’ to my installed apps, I get the error:

 

"django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.” Which is preceeded by this stack trace:

 

 

-------------------------BEGINNING OF TRACE ----------------------

Exception in thread django-main-thread:

Traceback (most recent call last):

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\utils.py", line 66, in __getitem__

    return self._engines[alias]

KeyError: 'django'

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "c:\users\joopa\anaconda3\envs\python38\lib\threading.py", line 932, in _bootstrap_inner

    self.run()

  File "c:\users\joopa\anaconda3\envs\python38\lib\threading.py", line 870, in run

    self._target(*self._args, **self._kwargs)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper

    fn(*args, **kwargs)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run

    autoreload.raise_last_exception()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception

    raise _exception[1]

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\core\management\__init__.py", line 375, in execute

    autoreload.check_errors(django.setup)()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper

    fn(*args, **kwargs)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\apps\registry.py", line 114, in populate

    app_config.import_models()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\apps\config.py", line 301, in import_models

    self.models_module = import_module(models_module_name)

  File "c:\users\joopa\anaconda3\envs\python38\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import

  File "<frozen importlib._bootstrap>", line 991, in _find_and_load

  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 848, in exec_module

  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\music_publisher\models.py", line 24, in <module>

    from .cwr_templates import (

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\music_publisher\cwr_templates.py", line 13, in <module>

    'HDR': Template(

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\base.py", line 148, in __init__

    engine = Engine.get_default()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\engine.py", line 76, in get_default

    for engine in engines.all():

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\utils.py", line 90, in all

    return [self[alias] for alias in self]

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\utils.py", line 90, in <listcomp>

    return [self[alias] for alias in self]

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\utils.py", line 81, in __getitem__

    engine = engine_cls(params)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\backends\django.py", line 25, in __init__

    options['libraries'] = self.get_templatetag_libraries(libraries)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\backends\django.py", line 43, in get_templatetag_libraries

    libraries = get_installed_libraries()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\backends\django.py", line 108, in get_installed_libraries

    for name in get_package_libraries(pkg):

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\template\backends\django.py", line 121, in get_package_libraries

    module = import_module(entry[1])

  File "c:\users\joopa\anaconda3\envs\python38\lib\importlib\__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\oscar\templatetags\category_tags.py", line 36, in <module>

    class CheapCategoryInfo(dict, metaclass=CategoryFieldPassThroughMetaClass):

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\oscar\templatetags\category_tags.py", line 27, in __new__

    for field in Category._meta.get_fields():

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\db\models\options.py", line 778, in get_fields

    return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\db\models\options.py", line 838, in _get_fields

    all_fields = self._relation_tree

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\utils\functional.py", line 48, in __get__

    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\db\models\options.py", line 751, in _relation_tree

    return self._populate_directed_relation_graph()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\db\models\options.py", line 721, in _populate_directed_relation_graph      

    all_models = self.apps.get_models(include_auto_created=True)

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\apps\registry.py", line 179, in get_models

    self.check_models_ready()

  File "C:\Users\joopa\Projects\Naija Sea - Oscar 3.1\.nj\lib\site-packages\django\apps\registry.py", line 141, in check_models_ready

    raise AppRegistryNotReady("Models aren't loaded yet.")

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

 

------------------------- END OF TRACE -------------------------------------------

 

 

Here is my installed apps:

 -----------------------------

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

 

    'django.contrib.sites',

    'django.contrib.flatpages',

    

 

    'oscar.config.Shop',

 

    # Overidden Oscar apps

    'oscarforks.analytics.apps.AnalyticsConfig',

    'oscarforks.checkout.apps.CheckoutConfig',

    'oscarforks.address.apps.AddressConfig',

    'oscarforks.shipping.apps.ShippingConfig',

    'oscarforks.catalogue.apps.CatalogueConfig',

    'oscarforks.communication.apps.CommunicationConfig',

    'oscarforks.partner.apps.PartnerConfig',

    'oscarforks.basket.apps.BasketConfig',

    'oscarforks.payment.apps.PaymentConfig',

    'oscarforks.offer.apps.OfferConfig',

    'oscarforks.order.apps.OrderConfig',

    'oscarforks.customer.apps.CustomerConfig',

    'oscarforks.search.apps.SearchConfig',

    'oscarforks.voucher.apps.VoucherConfig',

    'oscarforks.wishlists.apps.WishlistsConfig',

    

    #Submodule apps

    'oscar.apps.catalogue.reviews.apps.CatalogueReviewsConfig'# TODO Find out how to fork submodules

    

    # Oscar Dashboard apps

    'oscar.apps.dashboard.apps.DashboardConfig',

    'oscar.apps.dashboard.reports.apps.ReportsDashboardConfig',

    'oscar.apps.dashboard.users.apps.UsersDashboardConfig',

    'oscar.apps.dashboard.orders.apps.OrdersDashboardConfig',

    'oscar.apps.dashboard.catalogue.apps.CatalogueDashboardConfig',

    'oscar.apps.dashboard.offers.apps.OffersDashboardConfig',

    'oscar.apps.dashboard.partners.apps.PartnersDashboardConfig',

    'oscar.apps.dashboard.pages.apps.PagesDashboardConfig',

    'oscar.apps.dashboard.ranges.apps.RangesDashboardConfig',

    'oscar.apps.dashboard.reviews.apps.ReviewsDashboardConfig',

    'oscar.apps.dashboard.vouchers.apps.VouchersDashboardConfig',

    'oscar.apps.dashboard.communications.apps.CommunicationsDashboardConfig',

    'oscar.apps.dashboard.shipping.apps.ShippingDashboardConfig',

    

    # 3rd-party apps that oscar depends on

    'widget_tweaks',

    'haystack',

    'treebeard',

    'sorl.thumbnail',   # Default thumbnail backend, can be replaced

    'django_tables2',


    # MyAppsapps

    'apps.creators.apps.CreatorsConfig',

    'music_publisher.apps.MusicPublisherConfig',

]

 ---------------------

 

I have tried the suggestions on this thread:
Stackoverflow thread on a similar error with Models not loaded as well as other similar threads.

Here is my wsgi.py file:

 ---------------

import os

from django.core.wsgi import get_wsgi_application

 

os.environ.setdefault('DJANGO_SETTINGS_MODULE''backend.settings')

 

application = get_wsgi_application()

 -------------

I have no idea why it wont work...
Please let me know if you need more information on my end.

 

Many thanks in advance.

 

Sent from Mail for Windows

 

solari...@gmail.com

unread,
Sep 2, 2021, 12:41:14 AM9/2/21
to django-oscar
The issue is that django-music-publisher initialises a whole load of hard-coded templates during startup (see https://github.com/matijakolaric-com/django-music-publisher/blob/master/music_publisher/cwr_templates.py), which is imported from models.py . This in turn causes Django to look for and initialise all available template tags, including Oscar's, some of which rely on apps having been fully loaded first.

I think this is a problem with django-music-publisher - it should not be initialising templates in this way at startup, as it makes the invalid assumption that all template tags registered for a project do not rely on other models etc.

I can't see any obvious workaround - think you may need to ask the maintainers of that package to fix it.

Hope this helps,

Samir



Reply all
Reply to author
Forward
0 new messages