#16259: BaseDatabaseCreation.create_test_db() requires unexistant table.
--------------------+-----------------------------------
Reporter: zimnyx | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Testing framework
Version: SVN | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------+-----------------------------------
I don't have django.contrib.sites inside my installed apps, and despite
that BaseDatabaseCreation.create_test_db() assumes that I have Site model
which ends up with exception:
{{{
# BaseDatabaseCreation.create_test_db()
from django.db.models import get_model
Site = get_model('sites', 'Site')
if Site is not None and Site.objects.using(self.connection.alias).count()
== 1:
Site.objects.using(self.connection.alias).update(id=settings.SITE_ID)
Exception: django.db.utils.DatabaseError: relation "django_site" does not
exist
}}}
Why get_model() returns Site instead of None, despite I don't have sites
in my INSTALLED_APPS?
Because contenttypes (which I have in INSTALLED_APPS) does "from
django.contrib.sites.models import get_current_site", and in that moment
Site model gets registered.
{{{
/tmp/django/db/backends/creation.py(239)create_test_db()
-> load_initial_data=False)
/tmp/django/core/management/__init__.py(166)call_command()
-> return klass.execute(*args, **defaults)
/tmp/django/core/management/base.py(219)execute()
-> self.validate()
/tmp/django/core/management/base.py(243)validate()
-> from django.core.management.validation import get_validation_errors
/tmp/django/core/management/validation.py(3)<module>()
-> from django.contrib.contenttypes.generic import GenericForeignKey,
GenericRelation
/tmp/django/contrib/contenttypes/generic.py(14)<module>()
-> from django.contrib.admin.options import InlineModelAdmin,
flatten_fieldsets
/tmp/django/contrib/admin/__init__.py(6)<module>()
-> from django.contrib.admin.sites import AdminSite, site
/tmp/django/contrib/admin/sites.py(5)<module>()
-> from django.contrib.admin.forms import AdminAuthenticationForm
/tmp/django/contrib/admin/forms.py(4)<module>()
-> from django.contrib.auth.forms import AuthenticationForm
/tmp/django/contrib/auth/forms.py(4)<module>()
-> from django.contrib.sites.models import get_current_site
> /tmp/django/contrib/sites/models.py(6)<module>()
-> ...
}}}
My final question is: is get_model() a good way to determine if some model
is really "enabled" inside my project?
Maybe checking INSTALLED_APPS for application_name would be better
solution.
--
Ticket URL: <https://code.djangoproject.com/ticket/16259>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.