Opened 13 years ago

Closed 13 years ago

#16515 closed Bug (duplicate)

Testing with multiple databases assumes sites app installed on all of them

Reported by: Ryan Fugger Owned by: nobody
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: arv@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I am trying to run tests on a project with two databases. One of them has all the default django apps installed on them, including sites. The other has some of my own apps. When creating the test databases, I get the following error:

  [...]
  File "/home/ryan/projects/villages/django/db/backends/creation.py", line 256, in create_test_db
    if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
  File "/home/ryan/projects/villages/django/db/models/query.py", line 331, in count
    return self.query.get_count(using=self.db)
  File "/home/ryan/projects/villages/django/db/models/sql/query.py", line 406, in get_count
    number = obj.get_aggregation(using=using)[None]
  File "/home/ryan/projects/villages/django/db/models/sql/query.py", line 372, in get_aggregation
    result = query.get_compiler(using).execute_sql(SINGLE)
  File "/home/ryan/projects/villages/django/db/models/sql/compiler.py", line 754, in execute_sql
    cursor.execute(sql, params)
  File "/home/ryan/projects/villages/django/db/backends/postgresql_psycopg2/base.py", line 43, in execute
    return self.cursor.execute(query, args)
django.db.utils.DatabaseError: relation "django_site" does not exist
LINE 1: SELECT COUNT(*) FROM "django_site"

The problem seems to come from django.db.backends.creation.BaseDatabaseCreation.create_test_db, line 256, which checks if sites is installed, and then proceeds to query the sites table on the current database without checking that the sites table has even been created on the current database.

        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)

This code was introduced in [16027].

Change History (2)

comment:1 by Ryan Fugger, 13 years ago

Cc: arv@… added

comment:2 by Aymeric Augustin, 13 years ago

Resolution: duplicate
Status: newclosed

This really looks like #16353.

Note: See TracTickets for help on using tickets.
Back to Top