jrief / djangocms-cascade

Build Single Page Applications using the Django-CMS plugin system
MIT License
165 stars 85 forks source link

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

Closed quater closed 9 years ago

quater commented 9 years ago

I cannot get "djangocms-cascade 0.4.0" to work on Django CMS 3.0.7 with Django 1.7.1.

Environment

Prior to applying the "djangocms-cascade" specific settings, I verified that Django CMS is working.

Installed "djangocms-cascade 0.4.0" with below command:

pip install git+https://github.com/jrief/djangocms-cascade.git@0.4.0

pip freeze

(env)vagrant@vagrant-ubuntu-trusty-64:~/workspace$ pip freeze
Django==1.7.1
Django-Select2==4.2.2
Pillow==2.6.1
South==1.0.1
Unidecode==0.04.16
argparse==1.2.1
beautifulsoup4==4.3.2
dj-database-url==0.3.0
django-appconf==0.6
django-bootstrap3==5.0.2
django-classy-tags==0.5.1
django-cms==3.0.7
django-dbbackup==2.0.4
django-filer==0.9.8
django-mptt==0.6.1
django-polymorphic==0.6
django-reversion==1.8.5
django-sekizai==0.7
djangocms-admin-style==0.2.3
djangocms-cascade==0.4.0-alpha
djangocms-column==1.5
djangocms-file==0.1
djangocms-flash==0.1
djangocms-googlemap==0.2
djangocms-inherit==0.1
djangocms-installer==0.6.0
djangocms-link==1.5
djangocms-picture==0.1
djangocms-style==1.5
djangocms-teaser==0.1
djangocms-text-ckeditor==2.4.1
djangocms-video==0.1
easy-thumbnails==2.2
ecdsa==0.11
html5lib==0.999
jsonfield==1.0.0
paramiko==1.15.1
psycopg2==2.5.4
pycrypto==2.6.1
pyflakes==0.8.1
pysftp==0.2.8
pytz==2014.10
requests==2.5.0
six==1.8.0
wsgiref==0.1.2

"djangocms-cascade" specific settings in the "settings.py"

INSTALLED_APPS = (
...
'cmsplugin_cascade',
# 'cmsplugin_cascade.sharable',
'cms',
...
)
CMS_CASCADE_PLUGINS = ('cmsplugin_cascade.bootstrap3',)

Error when running 'makemigrations' or 'migrate'

(env)vagrant@vagrant-ubuntu-trusty-64:~/workspace$ python manage.py makemigrations
/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/publisher/manager.py:5: RemovedInDjango18Warning: `PublisherManager.get_query_set` method should be renamed `get_queryset`.
  class PublisherManager(models.Manager):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/models/managers.py:15: RemovedInDjango18Warning: `PageManager.get_query_set` method should be renamed `get_queryset`.
  class PageManager(PublisherManager):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/djangocms_googlemap/forms.py:14: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form GoogleMapForm needs updating
  class GoogleMapForm(ModelForm):

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cmsplugin_cascade/models.py", line 23, in <module>
    class PluginExtraFields(models.Model):
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cmsplugin_cascade/models.py", line 28, in PluginExtraFields
    CUSTOMIZABLE_PLUGINS = _plugins_for_site()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cmsplugin_cascade/models.py", line 19, in _plugins_for_site
    cascade_plugins = set([p for p in plugin_pool.get_all_plugins() if issubclass(p, ExtraFieldsMixin)])
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/plugin_pool.py", line 217, in get_all_plugins
    self.discover_plugins()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/plugin_pool.py", line 36, in discover_plugins
    load('cms_plugins')
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/utils/django_load.py", line 56, in load
    get_module(app, modname, verbose, failfast)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/utils/django_load.py", line 40, in get_module
    module = import_module(module_name)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 46, in import_module
    __import__(name)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/djangocms_inherit/cms_plugins.py", line 13, in <module>
    from .forms import InheritForm
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/djangocms_inherit/forms.py", line 11, in <module>
    class InheritForm(ModelForm):
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/djangocms_inherit/forms.py", line 13, in InheritForm
    label=_("page"), queryset=Page.objects.drafts(), required=False)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/models/managers.py", line 26, in drafts
    return super(PageManager, self).drafts()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/publisher/manager.py", line 14, in drafts
    return self.filter(publisher_is_draft=True)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 691, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/query.py", line 709, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1287, in add_q
    clause, require_inner = self._add_q(where_part, self.used_aliases)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1314, in _add_q
    current_negated=current_negated, connector=connector)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1138, in build_filter
    lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1076, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1339, in names_to_path
    field, model, direct, m2m = opts.get_field_by_name(name)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/options.py", line 416, in get_field_by_name
    cache = self.init_name_map()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/options.py", line 445, in init_name_map
    for f, model in self.get_all_related_m2m_objects_with_model():
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/options.py", line 563, in get_all_related_m2m_objects_with_model
    cache = self._fill_related_many_to_many_cache()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/db/models/options.py", line 577, in _fill_related_many_to_many_cache
    for klass in self.apps.get_models():
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
(env)vagrant@vagrant-ubuntu-trusty-64:~/workspace$ 

Research

The problem might to be related to this... https://docs.djangoproject.com/en/dev/releases/1.7/#standalone-scripts

jrief commented 9 years ago

Have you tried to run the reference implementation?

If I run

export DJANGO_SETTINGS_MODULE=bs3demo.settings
./manage.py makemigrations

I get quite a lot of warnings, but it works. I haven't tested all combinations, but can it be that the you have another order in INSTALLED_APPS? Please compare with the reference implementation.

quater commented 9 years ago

Thank you for your quick turnaround!

I have tried the reference implementation but stumbled over a different error. As suggested, I'll go through the list of 'INSTALLED_APPS' and remove everything which is not essential in order to narrow down. I will also check out the reference implementation again.

I'll keep you updated.

quater commented 9 years ago

You were right!

Still using my own instance, I have replaced the INSTALLED_APPS with the ones from the bs3demo.settings and the python manage.py makemigrations command run successfully.

settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'djangocms_admin_style',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.staticfiles',
    'django.contrib.sitemaps',
    'djangocms_text_ckeditor',
    'django_select2',
    'cmsplugin_cascade',
    'cmsplugin_cascade.sharable',
    'cms',
    'menus',
    'mptt',
    'filer',
    'easy_thumbnails',
    'sekizai',
    'project'
)

python manage.py migrate

(env)vagrant@vagrant-ubuntu-trusty-64:~/workspace$ python manage.py migrate
/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/publisher/manager.py:5: RemovedInDjango18Warning: `PublisherManager.get_query_set` method should be renamed `get_queryset`.
  class PublisherManager(models.Manager):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/models/managers.py:15: RemovedInDjango18Warning: `PageManager.get_query_set` method should be renamed `get_queryset`.
  class PageManager(PublisherManager):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/admin/change_list.py:39: RemovedInDjango18Warning: `CMSChangeList.get_query_set` method should be renamed `get_queryset`.
  class CMSChangeList(ChangeList):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/admin/forms.py:340: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form PagePermissionInlineAdminForm needs updating
  class PagePermissionInlineAdminForm(forms.ModelForm):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/admin/forms.py:442: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form ViewRestrictionInlineAdminForm needs updating
  class ViewRestrictionInlineAdminForm(PagePermissionInlineAdminForm):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/cms/admin/forms.py:491: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form PageUserForm needs updating
  class PageUserForm(UserCreationForm, GenericCmsPermissionForm):

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/forms/widgets.py:143: RemovedInDjango18Warning: `PagePermissionInlineAdmin.queryset` method should be renamed `get_queryset`.
  .__new__(mcs, name, bases, attrs))

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/forms/widgets.py:143: RemovedInDjango18Warning: `ViewRestrictionInlineAdmin.queryset` method should be renamed `get_queryset`.
  .__new__(mcs, name, bases, attrs))

/home/vagrant/workspace/env/local/lib/python2.7/site-packages/django/forms/widgets.py:143: RemovedInDjango18Warning: `PageUserAdmin.queryset` method should be renamed `get_queryset`.
  .__new__(mcs, name, bases, attrs))

Operations to perform:
  Synchronize unmigrated apps: filer, mptt, sharable, django_select2, djangocms_admin_style, sitemaps, sekizai, easy_thumbnails
  Apply all migrations: cmsplugin_cascade, sessions, admin, sites, auth, menus, contenttypes, cms, djangocms_text_ckeditor
Synchronizing apps without migrations:
  Creating tables...
    Creating table filer_folder
    Creating table filer_folderpermission
    Creating table filer_file
    Creating table filer_clipboard
    Creating table filer_clipboarditem
    Creating table filer_image
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying cmsplugin_cascade.0001_initial.../home/vagrant/workspace/env/local/lib/python2.7/site-packages/filer/fields/multistorage_file.py:106: SyntaxWarning: MultiStorageFileField can handle only File objects;<function generate_filename_multistorage at 0x7f1dfec4e398> passed
  "%s passed" % upload_to, SyntaxWarning)

 OK

In the light of this, this problem seems to be related to the order of the apps.

I have not yet figured out what resolves it for my Django CMS instance, provided I stick to the current set of applications, but I'll let you know the result.

quater commented 9 years ago

The problematic apps are djangocms_inherit and djangocms_link. It doesn't matter where about they are listed within INSTALLED_APPS. Once they are listed the problem is encountered.

To check out your Bootstrap example, I have created the vagrant startup script below. https://github.com/quater/djangocms-cascade-vagrant

Feel free to utilize this script as part of your repository.

jrief commented 9 years ago

What for is djangocms_inherit? djangocms_link is useless with djangocms-cascade anyway. All linking functionality (and more) is covered.

quater commented 9 years ago

I don't know what djangocms_inherit is for. It comes with the django-installer as part of the "standard plugin" along with djangocms-link.

Details can be seen here.

I'll change my deployment scripts so that they don't use the "django-installer" any more and then hand select the apps/ plugins in the future.