Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppRegistryNotReady exception #144

Closed
tsebire opened this issue Dec 13, 2015 · 23 comments
Closed

AppRegistryNotReady exception #144

tsebire opened this issue Dec 13, 2015 · 23 comments

Comments

@tsebire
Copy link

tsebire commented Dec 13, 2015

Hello,

I can't register a model in watson anymore since I've upgraded to Django 1.9.

It raises a AppRegistryNotReady exception. I'm using an AppConfig for my module set in my init.py file :

from django.apps import AppConfig
from watson import search as watson

class ProduitsConfig(AppConfig):
    name = "moderation.apps.produits"

    def ready(self):
        ProduitModel = self.get_model("Produit")
        watson.register(ProduitModel, fields=("nom", "marque__nom", "marque__pays__nom", "marque__region__nom", "type", "couleur"))

When I comment the watson import and the register line, I don't have any error.

Am I missing something ?

@etianen
Copy link
Owner

etianen commented Dec 13, 2015

Try upgrading to the latest django-watson.

https://github.com/etianen/django-watson/blob/master/CHANGELOG.markdown

On Sun, 13 Dec 2015 at 16:55, tsebire notifications@github.com wrote:

Hello,

I can't register a model in watson anymore since I've upgraded to Django 19

It raises a AppRegistryNotReady exception I'm using an AppConfig for my
module set in my __init__py file :

from djangoapps import AppConfigfrom watson import search as watson
class ProduitsConfig(AppConfig):
name = "moderationappsproduits"

def ready(self):
    ProduitModel = selfget_model("Produit")
    watsonregister(ProduitModel, fields=("nom", "marque__nom", "marque__pays__nom", "marque__region__nom", "type", "couleur"))

When I comment the watson import and the register line, I don't have any
error

Am I missing something ?


Reply to this email directly or view it on GitHub
#144.

@tsebire
Copy link
Author

tsebire commented Dec 14, 2015

I already did, that's why I don't know what can I do next. I'll retry tonight and keep you updated.

@etianen
Copy link
Owner

etianen commented Dec 14, 2015

Hmm, do you have a full traceback that I can investigate?

On Mon, 14 Dec 2015 at 09:00 tsebire notifications@github.com wrote:

I already did, that's why I don't know what can I do next. I'll retry
tonight and keep you updated.


Reply to this email directly or view it on GitHub
#144 (comment)
.

@tsebire
Copy link
Author

tsebire commented Dec 28, 2015

Here you go :

Traceback (most recent call last):
File "D:/Work/Sites/moderation/manage.py", line 10, in
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 350, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management__init__.py", line 176, in fetch_command
commands = get_commands()
File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 100, in wrapper
result = user_function(args, *kwds)
File "C:\Python27\lib\site-packages\django\core\management__init
.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "C:\Python27\lib\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.

@tsebire
Copy link
Author

tsebire commented Dec 28, 2015

I fixed the problem by putting the watson import in the ready method of AppConfig and not at the beginning of my file (it was working like this before).

Thanks for your time.

@fresh-django
Copy link

@tsebire thanks for posting your fix. I'd been looking at this for about 2 hours now!

@etianen
Copy link
Owner

etianen commented Jan 4, 2016

Out of interest, what causes the exception? It is running buildwatson, or
is it runserver?

I'm confused, because none of the unit tests pick up on this.

On Sun, 3 Jan 2016 at 23:39 fresh-django notifications@github.com wrote:

@tsebire https://github.com/tsebire thanks for posting your fix. I'd
been looking at this for about 2 hours now!


Reply to this email directly or view it on GitHub
#144 (comment)
.

@tsebire
Copy link
Author

tsebire commented Jan 4, 2016

It was thrown on runserver command.

@tsebire tsebire closed this as completed Jan 4, 2016
@etianen etianen reopened this Jan 4, 2016
@etianen
Copy link
Owner

etianen commented Jan 4, 2016

I'd like to keep this open for now. It should be possible to import watson at the top-level of your apps.py file. I'm not sure right now why it's not...

@tsebire
Copy link
Author

tsebire commented Jan 4, 2016

Ok my bad :). Good luck fixing this and happy new year.

@orf
Copy link

orf commented Jan 4, 2016

I'm also seeing this with Django 1.9.1:

from django.apps import AppConfig
from watson import search as watson

default_app_config = 'issues.IssueAppConfig'


class IssueAppConfig(AppConfig):
    name = "issues"

    def ready(self):
        software_v = self.get_model("SoftwareVersion")
        issue = self.get_model("IssueTranslation")
        watson.register(software_v)
        watson.register(issue)

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

@Athemis
Copy link

Athemis commented Jan 26, 2016

What worked for me is to move "from watson import search as watson" into the ready() function. No idea what's going on behind the scene though.

@etianen etianen closed this as completed in 7d876e5 Feb 4, 2016
@etianen
Copy link
Owner

etianen commented Feb 4, 2016

Check out the latest master branch. This should be fixed.

@etianen etianen reopened this Feb 4, 2016
@etianen
Copy link
Owner

etianen commented Feb 4, 2016

Keeping this issue open for now, until confirmation that it's fixed...

@actongorton
Copy link

@Athemis moving into ready() worked for me.

@vincevriend
Copy link

@etianen I tried it with the latest master branch. Unfortunately it still gives the same error:
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Moving the imports into the ready function still fixes it.

@etianen
Copy link
Owner

etianen commented Feb 29, 2016

Can I have the full traceback?

@vincevriend
Copy link

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x035E1B70>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
    six.reraise(*_exception)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Program Files (x86)\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "E:\Playground\Python\CaloriesNow\foodlog\apps.py", line 2, in <module>
    from watson import search as watson
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\watson\search.py", line 14, in <module>
    from django.contrib.contenttypes.models import ContentType
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\contrib\contenttypes\models.py", line 159, in <module>
    class ContentType(models.Model):
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\models\base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "C:\Program Files (x86)\Python35-32\lib\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.

@etianen
Copy link
Owner

etianen commented Mar 1, 2016

Oh, the ContentTypes framework. Gotcha.

Try the latest master now.

On Mon, 29 Feb 2016 at 15:03 TommySprat notifications@github.com wrote:

Unhandled exception in thread started by <function check_errors..wrapper at 0x035E1B70>
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(_args, *kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 249, in raise_last_exception
six.reraise(exception)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(args, **kwargs)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django__init
.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Program Files (x86)\Python35-32\lib\importlib__init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 944, in _find_and_load_unlocked
File "", line 222, in _call_with_frames_removed
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 662, in exec_module
File "", line 222, in _call_with_frames_removed
File "E:\Playground\Python\CaloriesNow\foodlog\apps.py", line 2, in
from watson import search as watson
File "C:\Program Files (x86)\Python35-32\lib\site-packages\watson\search.py", line 14, in
from django.contrib.contenttypes.models import ContentType
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\contrib\contenttypes\models.py", line 159, in
class ContentType(models.Model):
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\db\models\base.py", line 94, in new
app_config = apps.get_containing_app_config(module)
File "C:\Program Files (x86)\Python35-32\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "C:\Program Files (x86)\Python35-32\lib\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.


Reply to this email directly or view it on GitHub
#144 (comment)
.

@sunjoomoon
Copy link

I had the same issue but the issue RESOLVED as per Dave's advice to use the latest master branch. Thanks for the hard work.

@etianen
Copy link
Owner

etianen commented Mar 4, 2016

Cool, I'll release on Monday! :D
On Fri, 4 Mar 2016 at 05:12, sunjoomoon notifications@github.com wrote:

I had the same issue but the issue RESOLVED as per Dave's advice to use
the latest master branch. Thanks for the hard work.


Reply to this email directly or view it on GitHub
#144 (comment)
.

@vincevriend
Copy link

I also tried that latest master branch and can confirm that it's fixed on my system too.

@etianen
Copy link
Owner

etianen commented Mar 7, 2016

This is now released as 1.2.1

@etianen etianen closed this as completed Mar 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants