Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15542 closed Bug (worksforme)

When postgres autocommit is set contenttype test cause sites tests failures

Reported by: jasonculverhouse Owned by: nobody
Component: contrib.contenttypes Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

It seems that the contenttype framework and the sites contribs
conflict with using the autocommit:True database option. I'm not
really sure what happens but here is a simple test case that shows
that the order of the tests causes a failure. It looks like from the
SQL that the save point is being rolled back in a new transaction, not
the transaction that the savepoint was created.

If I create a new django tests site
with

django-admin-2.6.py startproject sitecontenttypebug

Modify settings.py to use postgres autocommit

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.postgresql_psycopg2',
       ...
       'OPTIONS': {
           "autocommit": True,
       }
   }
}

The minimum required to have the django tests fail is:

python manage.py test contenttypes sites.SitesFrameworkTests.test_get_current_site

Switching the order causes no failure

python manage.py test sites.SitesFrameworkTests.test_get_current_site contenttypes

Stack trace from the failure

======================================================================
ERROR: test_get_current_site
(django.contrib.sites.tests.SitesFrameworkTests)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/testcases.py", line 257, in __call__
   self._pre_setup()
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/testcases.py", line 224, in _pre_setup
   self._fixture_setup()
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/testcases.py", line 515, in _fixture_setup
   return super(TestCase, self)._fixture_setup()
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/testcases.py", line 236, in _fixture_setup
   call_command('flush', verbosity=0, interactive=False, database=db)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
   return klass.execute(*args, **defaults)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
   output = self.handle(*args, **options)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
   return self.handle_noargs(**options)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/commands/flush.py", line 75, in handle_noargs
   emit_post_sync_signal(all_models, verbosity, interactive, db)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/management/sql.py", line 182, in emit_post_sync_signal
   interactive=interactive, db=db)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/dispatch/dispatcher.py", line 172, in send
   response = receiver(signal=self, sender=sender, **named)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/contrib/auth/management/__init__.py", line 28, in create_permissions
   defaults={'name': name, 'content_type': ctype})
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/manager.py", line 135, in get_or_create
   return self.get_query_set().get_or_create(**kwargs)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 387, in get_or_create
   transaction.savepoint_rollback(sid, using=self.db)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/transaction.py", line 242, in savepoint_rollback
   connection._savepoint_rollback(sid)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/__init__.py", line 61, in _savepoint_rollback
   self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
   return self.cursor.execute(query, args)
DatabaseError: no such savepoint


----------------------------------------------------------------------
Ran 2 tests in 0.478s

FAILED (errors=1)
Destroying test database 'default'...

Offending SQL

LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SELECT "auth_permission"."id", "auth_permission"."name", "auth_permission"."content_type_id", "auth_permission"."codename" FROM "auth_permission"
WHERE ("auth_permission"."codename" = E'add_user'  AND "auth_permission"."content_type_id" = 3 )
LOG:  statement: SAVEPOINT s140735080041632_x1
LOG:  statement: INSERT INTO "auth_permission" ("name", "content_type_id", "codename") VALUES (E'Can add user', 3, E'add_user') RETURNING "auth_permission"."id"
LOG:  statement: COMMIT
ERROR:  insert or update on table "auth_permission" violates foreign key constraint "content_type_id_refs_id_728de91f"
DETAIL:  Key (content_type_id)=(3) is not present in table "django_content_type".
STATEMENT:  COMMIT
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: ROLLBACK TO SAVEPOINT s140735080041632_x1
ERROR:  no such savepoint
STATEMENT:  ROLLBACK TO SAVEPOINT s140735080041632_x1
LOG:  statement: SHOW default_transaction_isolation
LOG:  statement: BEGIN; SET TRANSACTION ISOLATION LEVEL READ COMMITTED
LOG:  statement: SET TIME ZONE E'America/Chicago'
LOG:  statement: ROLLBACK
LOG:  statement: DROP DATABASE "test_jason_db"

Attachments (0)

Change History (8)

comment:1 Changed 3 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.contenttypes

comment:2 Changed 3 years ago by lukeplant

  • Type set to Bug

comment:3 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:4 Changed 3 years ago by jacob

  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 3 years ago by ramiro

  • Description modified (diff)
  • Easy pickings unset
  • UI/UX unset

comment:6 Changed 3 years ago by ramiro

This might be a manifestation of #15117. Not completely sure as that ticket doesn't mention 'OPTIONS': {'autocommit: True} is involved.

comment:7 Changed 3 years ago by ramiro

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

I can't reproduce this with neither: the 1.3 release, the 1.3.X branch as of now, trunk as of now. Closing as worksforme.

comment:8 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.