amitu / importd

django based mini framework inspired from sinatra. fully compatible with django.
http://amitu.com/importd/
BSD 3-Clause "New" or "Revised" License
510 stars 30 forks source link

Error when trying to use django-schedule with importd #28

Closed santagada closed 10 years ago

santagada commented 10 years ago

When you try to syncdb it appears to first import the module, and only then tries to sync, so a piece of it tries to look up a contentype that doesn't exists yet.

app:

from importd import d d( INSTALLED_APPS = ['django.contrib.contenttypes', 'schedule'], TEMPLATE_CONTEXT_PROCESSORS=['django.contrib.auth.context_processors.auth', "django.core.context_processors.request",], ) if name == "main": d.main()

error message: Traceback (most recent call last): File "hey.py", line 5, in TEMPLATE_CONTEXT_PROCESSORS=['django.contrib.auth.context_processors.auth', "django.core.context_processors.request",], File "/home/projects/importd/importd/init.py", line 330, in call self._configure_django(*kw) File "/home/projects/importd/importd/init.py", line 278, in _configure_django import("{}.views".format(app)) # lint:ok File "/home/.virtualenvs/testd/lib/python2.7/site-packages/schedule/views.py", line 145, in template_name="schedule/edit_occurrence.html", _args, _kwargs): File "/home/.virtualenvs/testd/lib/python2.7/site-packages/schedule/utils.py", line 87, in init self.contenttype = ContentType.objects.get(app_label='schedule', model='event') File "/home/.virtualenvs/testd/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get return self.get_queryset().get(_args, *_kwargs) File "/home/.virtualenvs/testd/lib/python2.7/site-packages/django/db/models/query.py", line 307, in get self.model._meta.object_name) django.contrib.contenttypes.models.DoesNotExist: ContentType matching query does not exist.

kezabelle commented 10 years ago

This error occurs because of this decoratorwhich attempts to access the ContentType assuming everything is already set up.

The reason this issue manifests in importd is a side-effect of trying to import views in _configure_django under all circumstances. The likely solution would be to have _configure_django accept a autoimport boolean kwarg, which if set and is False, skips the looping and auto-importing of modules. This additional kwarg would then probably need to be applied to _act_as_manage and/or _handle_management_command

amitu commented 10 years ago

@kezabelle, good suggestion. Pull request?