#18510: Options._fill_related_objects_cache should assert for app_cache_ready() 
or
deal with app_cache_ready() == False
-------------------------------------+-------------------------------------
     Reporter:  vanschelven          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.4
  (models, ORM)                      |               Resolution:  fixed
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:  app-loading          |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

 * keywords:   => app-loading
 * status:  new => closed
 * resolution:   => fixed


Comment:

 This is "fixed" by the app-loading refactor, in the sense that Django now
 throws an explicit exception.

 '''stable/1.6.x -- obscure test failure'''

 {{{
 Creating test database for alias 'default'...
 E
 ======================================================================
 ERROR: test_get_field_by_name (testapp.tests.SimpleTest)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "~/django/django/db/models/options.py", line 371, in
 get_field_by_name
     return self._name_map[name]
 KeyError: 'userprofile'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "~/django/t18510/testapp/tests.py", line 10, in
 test_get_field_by_name
     User._meta.get_field_by_name('userprofile')
   File "~/django/django/db/models/options.py", line 377, in
 get_field_by_name
     % (self.object_name, name))
 django.db.models.fields.FieldDoesNotExist: User has no field named
 'userprofile'

 ----------------------------------------------------------------------
 Ran 1 test in 0.002s

 FAILED (errors=1)
 Destroying test database for alias 'default'...
 }}}

 '''stable/1.7.x -- explicit exception'''

 {{{
 Traceback (most recent call last):
   File "~/django/django/db/models/options.py", line 414, in
 get_field_by_name
     return self._name_map[name]
 AttributeError: 'Options' object has no attribute '_name_map'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "~/django/django/db/models/options.py", line 559, in
 get_all_related_m2m_objects_with_model
     cache = self._related_many_to_many_cache
 AttributeError: 'Options' object has no attribute
 '_related_many_to_many_cache'

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "./manage.py", line 10, in <module>
     execute_from_command_line(sys.argv)
   File "~/django/django/core/management/__init__.py", line 385, in
 execute_from_command_line
     utility.execute()
   File "~/django/django/core/management/__init__.py", line 354, in execute
     django.setup()
   File "~/django/django/__init__.py", line 21, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "~/django/django/apps/registry.py", line 106, in populate
     app_config.import_models(all_models)
   File "~/django/django/apps/config.py", line 190, in import_models
     self.models_module = import_module(models_module_name)
   File "~/.virtualenvs/django/lib/python3.4/importlib/__init__.py", line
 104, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
   File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
   File "<frozen importlib._bootstrap>", line 2203, in
 _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 1129, in _exec
   File "<frozen importlib._bootstrap>", line 1448, in exec_module
   File "<frozen importlib._bootstrap>", line 321, in
 _call_with_frames_removed
   File "~/django/t18510/testapp/models.py", line 5, in <module>
     User._meta.get_field_by_name('username')
   File "~/django/django/db/models/options.py", line 416, in
 get_field_by_name
     cache = self.init_name_map()
   File "~/django/django/db/models/options.py", line 445, in init_name_map
     for f, model in self.get_all_related_m2m_objects_with_model():
   File "~/django/django/db/models/options.py", line 561, in
 get_all_related_m2m_objects_with_model
     cache = self._fill_related_many_to_many_cache()
   File "~/django/django/db/models/options.py", line 575, in
 _fill_related_many_to_many_cache
     for klass in self.apps.get_models():
   File "~/.virtualenvs/django/lib/python3.4/functools.py", line 428, in
 wrapper
     result = user_function(*args, **kwds)
   File "~/django/django/apps/registry.py", line 156, in get_models
     self.check_ready()
   File "~/django/django/apps/registry.py", line 119, in check_ready
     raise RuntimeError("App registry isn't ready yet.")
 RuntimeError: App registry isn't ready yet.
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18510#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.126952fb7b038ba75c2fe2f751d15467%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to