Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#15850 closed Bug (fixed)

Test runner fails when sites app not installed

Reported by: adsva Owned by: Carl Meyer
Component: Testing framework Version: master
Severity: Normal Keywords:
Cc: schmilblick Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I don't have 'sites' in INSTALLED_APPS, and Changeset [16028] seems to break the test runner.

Selected bits from the test traceback:

Traceback (most recent call last):


  File ".../django/db/backends/", line 256, in create_test_db
    if Site is not None and Site.objects.using(self.connection.alias).count() == 1:
  File ".../django/db/models/", line 334, in count
    return self.query.get_count(using=self.db)
  File ".../django/db/models/sql/", line 401, in get_count
    number = obj.get_aggregation(using=using)[None]
  File ".../django/db/models/sql/", line 367, in get_aggregation
    result = query.get_compiler(using).execute_sql(SINGLE)
  File ".../django/db/models/sql/", line 735, in execute_sql
    cursor.execute(sql, params)
  File ".../django/db/backends/sqlite3/", line 226, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: django_site

I'm wondering if Site = get_model('sites', 'Site') is really a good way to check if the sites is installed. Looks like as soon as the Sites model is declared it registers itself to be discovered by get_model?

Change History (6)

comment:1 Changed 9 years ago by schmilblick

Cc: schmilblick added

comment:2 Changed 9 years ago by Carl Meyer

Owner: changed from nobody to Carl Meyer
Status: newassigned
Triage Stage: UnreviewedAccepted

Yes, I am seeing this problem as well. #15866 is the root cause, so my first approach is going to be fixing that.

Not closing this as duplicate, though, because it would be possible to fix this (by changing r16027) if fixing #15866 turns out to be quite difficult.

comment:3 Changed 9 years ago by Carl Meyer

Resolution: fixed
Status: assignedclosed

In [16053]:

(The changeset message doesn't reference this ticket)

comment:4 Changed 9 years ago by Carl Meyer

Easy pickings: unset

This also needs to be fixed in 1.3.X. Backporting the fix for #15866 is not acceptable as a solution, because #15866 is not a regression and the fix is backwards-incompatible (albeit only to private internal API). I've proposed at that the best answer would be to modify the fix for #15573 to check INSTALLED_APPS rather than the return value of get_model - but I'd prefer if someone with access to test on Oracle would make that change.

comment:5 Changed 9 years ago by Ian Kelly

In [16062]:

[1.3.X] Refs #15573, #15850: Added a check for whether the sites app is installed when creating the test database, in order to work around a bug in get_model. Thanks to adsva and carljm.

comment:6 Changed 7 years ago by Aymeric Augustin <aymeric.augustin@…>

In 9f13c3328199d2fa70235cdc63bb06b1efc5b117:

Removed the only_installed argument of Apps.get_models.

Refs #15903, #15866, #15850.

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