Opened 4 years ago

Closed 4 years ago

Last modified 3 months ago

#15573 closed Bug (fixed)

runtests.py sets incorrect SITE_ID when using Oracle

Reported by: ikelly Owned by: nobody
Component: Testing framework Version: master
Severity: Normal Keywords: oracle site_id
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

Running the test suite under Oracle currently generates a large number of errors that look like this:

======================================================================
ERROR: test_shortcut_view (django.contrib.contenttypes.tests.ContentTypesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Django\django.trunk\django\contrib\contenttypes\tests.py", line 66, in test_shortcut_view
    current_site = Site.objects.get_current()
  File "C:\Django\django.trunk\django\contrib\sites\models.py", line 26, in get_current
    current_site = self.get(pk=sid)
  File "C:\Django\django.trunk\django\db\models\manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "C:\Django\django.trunk\django\db\models\query.py", line 349, in get
    % self.model._meta.object_name)
DoesNotExist: Site matching query does not exist.

----------------------------------------------------------------------

This seems to be a result of r14537. Since the test setup does a syncdb followed by a flush on each database, the default Site object gets created twice. Since the sequence reset no longer decreases the sequence value, the second Site object created, the one that sticks around and gets used for the tests, has an id of 2 instead of 1. However, runtests.py forces the SITE_ID setting to be 1.

Change History (12)

comment:1 Changed 4 years ago by ikelly

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.2 to SVN

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 4 years ago by ikelly

A related problem occurs elsewhere: the fixtures for the flatpages tests use a hard-coded site id of 1. Maybe the best way to fix this is going to be to find a way to coerce the default site id to be 1 when running the test suite.

comment:4 Changed 4 years ago by lukeplant

  • Type set to Bug

comment:5 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:6 Changed 4 years ago by ikelly

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

In [16027]:

Fixed #15573: Forced the default site id to be 1 when creating test databases, to prevent a large number of errors when running the tests using the oracle backend.

comment:7 Changed 4 years ago by ikelly

In [16028]:

[1.3.X] Fixed #15573: Forced the default site id to be 1 when creating
test databases, to prevent a large number of errors when running the
tests using the oracle backend. Backport of r16027 from trunk.

comment:8 Changed 4 years ago by carljm

  • Easy pickings unset

This change broke running of tests in a project without contrib.sites installed (#15850), due to the underlying issue #15866. I've fixed #15866 in trunk, but wasn't planning to backport to 1.3.X for stability reasons, since #15866 itself is not a regression and the fix changes the behavior of (internal and undocumented) methods in a backwards-incompatible way.

However, #15850 is a significant regression and still needs fixing in 1.3.X. I think the least-invasive approach there will be to modify the change made in r16028 to check INSTALLED_APPS for django.contrib.sites rather than using the return value of get_model. I don't feel comfortable making that change myself, though, since I don't have Oracle available to ensure that the fix still works for the original purpose.

Ian, would you be able to make that change in 1.3.X?

comment:9 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 3 years ago by carljm

In [16868]:

Fixed #16353 -- don't try to create Site objects on all databases. Refs #15573, #15346. Thanks Aymeric Augustin for the report and the patch.

comment:11 Changed 3 years ago by carljm

In [16869]:

[1.3.X] Fixed #16353 -- don't try to create Site objects on all databases. Refs #15573, #15346. Thanks Aymeric Augustin for the report and the patch.

Backport of r16868 in trunk.

comment:12 Changed 3 months ago by Tim Graham <timograham@…>

In 1f98ec2e53e4636863396ab54f671f4546f9ba4c:

Fixed #23929 -- Added more tests for create_default_site.

Refs: #15346, #15573, #16353, #16828.

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