2016-05-11 13 views
0

Der Versuch, django-shopify-sync in einem Django 1.9-Projekt zu verwenden. Beim Laden der Konfiguration für die App gibt es den folgenden Fehler, wahrscheinlich, weil es versucht, einige Modelle in der Konfiguration zu laden?Django 1.9 django.core.exceptions.AppRegistryNotReady: Die Apps sind noch nicht geladen

Versucht, die beiden Importe zu verschieben, die schließlich Modelle in die ready() -Funktion importieren, aber immer noch den gleichen Fehler bekommen. Culpirt Linien 2 und 3 in der folgenden Datei https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/apps.py

Der Fehler ist:

$ python manage.py runserver 
Unhandled exception in thread started by <function wrapper at 0x10753e500> 
Traceback (most recent call last): 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run 
    autoreload.raise_last_exception() 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception 
    six.reraise(*_exception) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper 
    fn(*args, **kwargs) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/__init__.py", line 18, in setup 
    apps.populate(settings.INSTALLED_APPS) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate 
    app_config = AppConfig.create(entry) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/config.py", line 116, in create 
    mod = import_module(mod_path) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
    File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/apps.py", line 2, in <module> 
    from shopify_sync.handlers import webhook_received_handler 
    File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/handlers.py", line 3, in <module> 
    from .models import (CustomCollection, Customer, Order, Product, Shop, 
    File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/__init__.py", line 3, in <module> 
    from .address import Address 
    File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/address.py", line 6, in <module> 
    from .base import ShopifyResourceModel 
    File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/base.py", line 144, in <module> 
    class ShopifyResourceModel(models.Model): 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__ 
    app_config = apps.get_containing_app_config(module) 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config 
    self.check_apps_ready() 
    File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready 
    raise AppRegistryNotReady("Apps aren't loaded yet.") 
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. 

UPDATE: Wenn ich die folgenden Zeilen (Modell Importe) https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4 nach innen get_topic_models bewegen scheint es, um den Fehler zu beheben. Aber das ist irgendwie schmutzig, kann jemand eine bessere Lösung finden?

+0

Das sieht sicherlich wie der Schuldige, aber nicht schuldig, bis bewiesen. Sehen Sie diesen Fehler, wenn Sie ./manage.py runserver oder mit etwas anderem tun – e4c5

+0

@ e4c5 wenn Sie den Server ausführen, ja – Andres

+0

Sie haben shopify-sync als App in INSTALLED_APPS registriert? – e4c5

Antwort

0

Es sieht so aus, als könnten Sie ein Bestellproblem haben. Stellen Sie sicher, dass sich Ihre Anwendung im INSTALLED_APPS Tupel nach django-shopify-sync befindet. Sie können ein paar weitere Details in der Application registry documentation finden.

So unbefriedigend wie ein Inline-Import ist, können Sie damit festgefahren sein. Ich würde vorschlagen,

from shopify_sync.handlers import webhook_received_handler 
from shopify_webhook.signals import webhook_received 

in die ready Methode in apps.py bewegen. Dies verzögert den Import, bis die Modelle fertig sind.

Die Veränderung, die ich versuchte, ist:

diff --git a/shopify_sync/apps.py b/shopify_sync/apps.py 
index 663b43b..0bc1fcc 100644 
--- a/shopify_sync/apps.py 
+++ b/shopify_sync/apps.py 
@@ -1,7 +1,5 @@ 
from django.apps import AppConfig 
-from shopify_sync.handlers import webhook_received_handler 
-from shopify_webhook.signals import webhook_received 
- 
+import importlib 

class ShopifySyncConfig(AppConfig): 
    """ 
@@ -16,5 +14,9 @@ class ShopifySyncConfig(AppConfig): 
     The ready() method is called after Django setup. 
     """ 

+  signals_webhook_received = importlib.import_module('.signals', package='shopify_webhook') 
+  handlers_webhook_received_handler = importlib.import_module('.handlers', package='shopify_sync') 
+ 
     # Connect shopify_webhook's webhook_received signal to our synchronisation handler. 
-  webhook_received.connect(webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler') 
+  signals_webhook_received.webhook_received.connect(handlers_webhook_received_handler.webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler') 
+ 
+0

django-shopify-sync ist die Anwendung, die ich hinzufügen möchte. Auf welche andere Anwendung beziehen Sie sich? – Andres

+0

Mein schlechtes, ich habe deine Frage missverstanden. Lass mich etwas näher hinschauen. –

+0

@Andres: Die Antwort sollte jetzt relevant sein. –

Verwandte Themen