Opened 4 years ago

Closed 4 years ago

Last modified 16 months ago

#15850 closed Bug (fixed)

Test runner fails when sites app not installed

Reported by: adsva Owned by: carljm
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:

Description

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

Selected bits from the manage.py test traceback:

Traceback (most recent call last):

  ...

  File ".../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 ".../django/db/models/query.py", line 334, in count
    return self.query.get_count(using=self.db)
  File ".../django/db/models/sql/query.py", line 401, in get_count
    number = obj.get_aggregation(using=using)[None]
  File ".../django/db/models/sql/query.py", line 367, in get_aggregation
    result = query.get_compiler(using).execute_sql(SINGLE)
  File ".../django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File ".../django/db/backends/sqlite3/base.py", 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 4 years ago by schmilblick

  • Cc schmilblick added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by carljm

  • Owner changed from nobody to carljm
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by carljm

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16053]:

(The changeset message doesn't reference this ticket)

comment:4 Changed 4 years ago by carljm

  • 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 http://code.djangoproject.com/ticket/15573#comment:8 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 4 years ago by ikelly

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 16 months 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