data_collector changes for django >= 1.7 #1556

Closed
MFlyer opened this Issue Nov 30, 2016 · 0 comments

Projects

None yet

2 participants

@MFlyer
Member
MFlyer commented Nov 30, 2016

Hi @schakrava , need your help / confirmation for upcoming PR:

While checking Pincard manager after Django update got this while trying to create a new pincard (credit card symbol on users page clicked):

Traceback (most recent call last):
  File "/opt/build/eggs/gevent-1.1.2-py2.7-linux-x86_64.egg/gevent/greenlet.py", line 534, in run
    result = self._run(*self.args, **self.kwargs)
  File "/opt/build/src/rockstor/smart_manager/data_collector.py", line 96, in create_pincard
    new_pincard = save_pincard(uid)
  File "/opt/build/src/rockstor/system/pinmanager.py", line 171, in save_pincard
    flush_pincard(uid)
  File "/opt/build/src/rockstor/system/pinmanager.py", line 163, in flush_pincard
    Pincard.objects.filter(user=int(uid)).delete()
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/query.py", line 536, in delete
    collector.collect(del_query)
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/deletion.py", line 193, in collect
    if self.can_fast_delete(objs):
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/deletion.py", line 155, in can_fast_delete
    for related in get_candidate_relations_to_delete(opts):
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/deletion.py", line 62, in get_candidate_relations_to_delete
    opts.get_fields(include_hidden=True) for opts in candidate_models
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/deletion.py", line 62, in <genexpr>
    opts.get_fields(include_hidden=True) for opts in candidate_models
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/options.py", line 740, in get_fields
    return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/options.py", line 802, in _get_fields
    all_fields = self._relation_tree
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/utils/functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/options.py", line 709, in _relation_tree
    return self._populate_directed_relation_graph()
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/db/models/options.py", line 681, in _populate_directed_relation_graph
    all_models = self.apps.get_models(include_auto_created=True)
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/opt/build/eggs/Django-1.8.16-py2.7.egg/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.
<Greenlet at 0x22e8cd0: create_pincard(u'11201')> failed with AppRegistryNotReady

Googling found that it's related to Django >=1.7 and solved over system.pinmanager this with:

import django
django.setup()

Pinmanager code inside data_collector (remember data_collector is supervisord, not on our wsgi) relies on system.pinmanager that loads Django User model (from django.contrib.auth.models import User as DjangoUser), but django.setup() now seems to be required

Can you confirm this being ok? :)

Meanwhile, having PR
M.

@schakrava schakrava pushed a commit that closed this issue Dec 4, 2016
@MFlyer MFlyer Fixes #1556 adding Django env
Signed-off-by: Mirko Arena <mirko.arena@gmail.com>
1af716c
@schakrava schakrava closed this in 1af716c Dec 4, 2016
@schakrava schakrava added the bug label Dec 4, 2016
@schakrava schakrava added this to the Pinnacles milestone Dec 4, 2016
@MFlyer MFlyer was assigned by schakrava Dec 4, 2016
@schakrava schakrava changed the title from [Bug] Upgrading to Django >= 1.7 requires enabling Django on data_collector to data_collector changes for django >= 1.7 Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment