TAXIIProject / yeti

YETI is a TAXII implementation
BSD 3-Clause "New" or "Revised" License
46 stars 19 forks source link

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet. #85

Closed AdamTheAnalyst closed 8 years ago

AdamTheAnalyst commented 8 years ago

When uncommenting:

taxii_services.register_message_handlers()

In

yeti/__init__.py 

Throws the following error:

Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 385, in execute_from_command_line utility.execute() File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 345, in execute settings.INSTALLED_APPS File "/usr/lib/python2.7/site-packages/django/conf/init.py", line 46, in getattr self._setup(name) File "/usr/lib/python2.7/site-packages/django/conf/init.py", line 42, in _setup self._wrapped = Settings(settings_module) File "/usr/lib/python2.7/site-packages/django/conf/init.py", line 94, in init mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib64/python2.7/importlib/init.py", line 37, in import_module import(name) File "/root/yeti/yeti/init.py", line 8, in taxii_services.register_message_handlers() File "/usr/lib/python2.7/site-packages/taxii_services/init.py", line 61, in register_message_handlers management.register_message_handler(handler) File "/usr/lib/python2.7/site-packages/taxii_services/management.py", line 40, in register_message_handler mh, created = MessageHandler.objects.get_or_create(handler=handler_string) File "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method return getattr(self.get_queryset(), name)(_args, _kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 422, in get_or_create return self.get(_lookup), False File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 345, in get clone = self.filter(_args, _kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 691, in filter return self._filter_or_exclude(False, args, _kwargs) File "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 709, in _filter_or_exclude clone.query.add_q(Q(_args, _kwargs)) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1331, in add_q clause, require_inner = self._add_q(where_part, self.used_aliases) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1358, in _add_q current_negated=current_negated, connector=connector) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1182, in build_filter lookups, parts, reffed_aggregate = self.solve_lookup_type(arg) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1120, in solve_lookuptype , field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta()) File "/usr/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1383, in names_to_path field, model, direct, m2m = opts.get_field_by_name(name) File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 416, in get_field_by_name cache = self.init_name_map() File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 445, in init_name_map for f, model in self.get_all_related_m2m_objects_with_model(): File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 563, in get_all_related_m2m_objects_with_model cache = self._fill_related_many_to_many_cache() File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 570, in _fill_related_many_to_many_cache for obj, model in parent._meta.get_all_related_m2m_objects_with_model(): File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 563, in get_all_related_m2m_objects_with_model cache = self._fill_related_many_to_many_cache() File "/usr/lib/python2.7/site-packages/django/db/models/options.py", line 577, in _fill_related_many_to_many_cache for klass in self.apps.get_models(): File "/usr/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper result = user_function(_args, *_kwds) File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 168, in get_models self.check_models_ready() File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready raise AppRegistryNotReady("Models aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Installed:

django==1.7.4
django-solo==1.1.0
libtaxii==1.1.105
taxii_services==0.4
gtback commented 8 years ago

Hi @AdamTheAnalyst! I'll try to take a look at this soon, but in the meantime, depending on what you are trying to do, I would look at using https://github.com/EclecticIQ/OpenTAXII/ instead. It's more actively maintained, and more geared toward "production" use.

That said, if you figure out a bug, we're happy to accept pull requests! I've seen this error from Django before, and it's usually a pretty straightforward fix.

gtback commented 8 years ago

Turned out to be an easy fix 😀 . Thanks @AdamTheAnalyst !

avi30155 commented 7 years ago

i had the same problem. could you explain the sulution?

gtback commented 7 years ago

It's been a while since I had to look at this, but I think in newer versions of Django, the django.setup() function needs to be explicitly called before trying to do anything with models (like saving data to the database).

@avi30155, what versions of Python and Django are you using? The output from pip list will be helpful too. Thanks!

avi30155 commented 7 years ago

Hi. Thanks for your comment. This is the full error message: (ENV) C:\Python27\Scripts\ENV> c:\Users\operator\Desktop\YETI\yeti-2.0a5\manage.py syncdb Traceback (most recent call last): File "C:\Users\operator\Desktop\YETI\yeti-2.0a5\manage.py", line 5, in

django.setup() File "C:\Python27\lib\site-packages\django\__init__.py", line 22, in setup configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__ self._setup(name) File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 39, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings i'm using python 2.7.13 and django 1.11.2 And this is my pip list: Django (1.11.2) django-solo (1.1.2) libtaxii (1.1.111) lxml (3.8.0) pip (9.0.1) python-dateutil (2.6.0) pytz (2017.2) setuptools (36.0.1) six (1.10.0) taxii-services (0.4) wheel (0.29.0) i was enter the django.setup() and still same error message. Thanks an regards. Avi 2017-06-26 16:34 GMT+03:00 Greg Back : > It's been a while since I had to look at this, but I think in newer > versions of Django, the django.setup() function needs to be explicitly > called before trying to do anything with models (like saving data to the > database). > > @avi30155 , what versions of Python and > Django are you using? The output from pip list will be helpful too. > Thanks! > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > , > or mute the thread > > . >
gtback commented 7 years ago

Hi @avi30155. YETI was not designed to work with the latest versions of Django; YETI hasn't really been updated in a few years, so I'm not surprised there's a bug with the newest versons. I'm a bit surprised by that particular error, since manage.py defines DJANGO_SETTINGS_MODULE, but I tried to reproduce and was running into various other issues.

Make sure you're using the latest version of the master branch (not the 2.0a5 release tag). The django.setup() call is already in yeti/__init__.py. If you're still running into problems, please open a new issue, since I think what you're running into may be separate from this one.

avi30155 commented 7 years ago

Thanks a lot! i just got lower version of django, and it is resolve all errors.

2017-06-28 20:07 GMT+03:00 Greg Back notifications@github.com:

Hi @avi30155 https://github.com/avi30155. YETI was not designed to work with the latest versions of Django; YETI hasn't really been updated in a few years, so I'm not surprised there's a bug with the newest versons. I'm a bit surprised by that particular error, since manage.py defines DJANGO_SETTINGS_MODULE, but I tried to reproduce and was running into various other issues.

Make sure you're using the latest version of the master branch (not the 2.0a5 release tag). The django.setup() call is already in yeti/init.py. If you're still running into problems, please open a new issue, since I think what you're running into may be separate from this one.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/TAXIIProject/yeti/issues/85#issuecomment-311725009, or mute the thread https://github.com/notifications/unsubscribe-auth/AcTjIsWL9xEGeNnGsGdXTrT8XBjdizj0ks5sIohCgaJpZM4Jqp5e .

gtback commented 7 years ago

Glad that helped!