etianen / django-watson

Full-text multi-table search application for Django. Easy to install and use, with good performance.
BSD 3-Clause "New" or "Revised" License
1.2k stars 129 forks source link

AppRegistryNotReady exception #144

Closed tsebire closed 8 years ago

tsebire commented 8 years ago

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 commented 8 years ago

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 initpy 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 https://github.com/etianen/django-watson/issues/144.

tsebire commented 8 years ago

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

etianen commented 8 years ago

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 https://github.com/etianen/django-watson/issues/144#issuecomment-164382094 .

tsebire commented 8 years ago

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\managementinit.py", line 350, in execute_from_command_line utility.execute() File "C:\Python27\lib\site-packages\django\core\managementinit.py", line 342, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\managementinit.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\managementinit.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 commented 8 years ago

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 commented 8 years ago

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

etianen commented 8 years ago

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 https://github.com/etianen/django-watson/issues/144#issuecomment-168554762 .

tsebire commented 8 years ago

It was thrown on runserver command.

etianen commented 8 years ago

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 commented 8 years ago

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

orf commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

etianen commented 8 years ago

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

actongorton commented 8 years ago

@Athemis moving into ready() worked for me.

vincevriend commented 8 years ago

@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 commented 8 years ago

Can I have the full traceback?

vincevriend commented 8 years ago
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 commented 8 years ago

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\djangoinit__.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\importlibinit.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 https://github.com/etianen/django-watson/issues/144#issuecomment-190248996 .

sunjoomoon commented 8 years ago

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 commented 8 years ago

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 https://github.com/etianen/django-watson/issues/144#issuecomment-192108160 .

vincevriend commented 8 years ago

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

etianen commented 8 years ago

This is now released as 1.2.1