ImperialCollegeLondon / django-drf-filepond

A Django app providing a server implemention for the Filepond file upload library
BSD 3-Clause "New" or "Revised" License
105 stars 40 forks source link

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. #11

Closed casoetan closed 5 years ago

casoetan commented 5 years ago

Using the first option throws

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

Full Trace

Traceback (most recent call last):
  File "./manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/User/aaa/Sites/Projects/django-apps/py3.7-clop/backend/app/project/common/apps.py", line 7, in <module>
    from project.common.utils import AppGroupPermissions, AuthGroups, Permissions
  File "/User/aaa/Sites/Projects/django-apps/py3.7-clop/backend/app/project/common/utils/__init__.py", line 6, in <module>
    from ._file_upload import *  # noqa
  File "/User/aaa/Sites/Projects/django-apps/py3.7-clop/backend/app/project/common/utils/_file_upload.py", line 4, in <module>
    from django_drf_filepond.models import TemporaryUpload
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django_drf_filepond/models.py", line 27, in <module>
    class TemporaryUpload(models.Model):
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/db/models/base.py", line 87, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/apps/registry.py", line 249, in get_containing_app_config
    self.check_apps_ready()
  File "/User/aaa/.pyenv/versions/py3.7-clop/lib/python3.7/site-packages/django/apps/registry.py", line 132, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
jcohen02 commented 5 years ago

Using the first option throws

Sorry, can you clarify what you mean here by the first option - looks from the trace like you're running a management command (runserver?). Is this in relation to another issue? I'm assuming this is independent of the other issues but will need a little more information to investigate this. Thanks.

casoetan commented 5 years ago

I'm sorry for not clarifying. I meant 1. Manual handling of file storage.

Basically any import of TemporaryUpload throws that (without even using it). I haven't been able to dig further. Maybe this evening.

The option I meant...

import os
from django_drf_filepond.models import TemporaryUpload

# Get the temporary upload record
tu = TemporaryUpload.objects.get(upload_id='<22-char unique ID>')

# Move the file somewhere for permanent storage
# The file will be saved with its original name
os.rename(tu.get_file_path(), '/path/to/permanent/location/%s' % tu.upload_name)

# Delete the temporary upload record and the temporary directory
tu.delete()
jcohen02 commented 5 years ago

Thanks for the clarification, if you have a chance to investigate this later and can provide further details, that would be great. I'll also aim to take a look into this.

jcohen02 commented 5 years ago

Just to provide an update on this, I've tested using a simple standalone test case as follows:

mkdir test-app; cd test-app
virtualenv test-env; source test-env/bin/activate
pip install Django django-drf-filepond
django-admin startproject testproject .

Now edit settings and add 'django_drf_filepond' _to INSTALLEDAPPS as described in section 1 of configuration

Now create the database and enter a Django shell:

python manage.py migrate
python manage.py shell

Within the shell, the following now works fine for me:

from django_drf_filepond.models import TemporaryUpload

I've tested using the following environment: Python: 3.6.6 and 3.7.2 Django: 2.1.7 django-drf-filepond: 0.0.5

The error you're getting looks to be the result of some sort of Django configuration issue. If you could try the above test case and see if this works that would be good to know. If you are able to produce a similar test case that reproduces the problem, that would also be very useful.

casoetan commented 5 years ago

That works. Will investigate further what the issue may be. Thanks

casoetan commented 5 years ago

Noticed the issue. The that requires this package housing this loads earlier than the app where this was defined.

Thanks