Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#12766 closed (fixed)

custom_pk test fails with psycopg1 backend

Reported by: kmtracey Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

F
======================================================================
FAIL: Doctest: modeltests.custom_pk.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.custom_pk.models.__test__.API_TESTS
  File "D:\u\kmt\django\trunk\tests\modeltests\custom_pk\models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "D:\u\kmt\django\trunk\tests\modeltests\custom_pk\models.py", line ?, in modeltests.custom_pk.models.__test__.API_T
ESTS
Failed example:
    try:
       sid = transaction.savepoint()
       Employee.objects.create(employee_code=123, first_name='Fred', last_name='Jones')
       transaction.savepoint_commit(sid)
    except Exception, e:
       if isinstance(e, IntegrityError):
           transaction.savepoint_rollback(sid)
           print "Pass"
       else:
           print "Fail with %s" % type(e)
Expected:
    Pass
Got:
    Fail with <class 'django.db.utils.DatabaseError'>

Followed by a bunch more errors resulting from the uncleared error on the connection.

Change History (8)

comment:1 Changed 6 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

force_insert_update, get_or_create, and one_to_one tests all fail similarly. In all cases test is looking for an IntegrityError and getting a DatabaseError instead.

comment:2 Changed 6 years ago by kmtracey

Note these tests all fail prior to r12352; these errors were not introduced by the implementation of a common class for database errors. With r12351 results show psycopg1 is raising ProgrammingError where IntegrityError is expected by the tests. For example:

F
======================================================================
FAIL: Doctest: modeltests.custom_pk.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "d:\u\kmt\django\trunk\django\test\_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for modeltests.custom_pk.models.__test__.API_TESTS
  File "D:\u\kmt\django\trunk\tests\modeltests\custom_pk\models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "D:\u\kmt\django\trunk\tests\modeltests\custom_pk\models.py", line ?, in modeltests.custom_pk.models.__test__.API_TESTS
Failed example:
    try:
       sid = transaction.savepoint()
       Employee.objects.create(employee_code=123, first_name='Fred', last_name='Jones')
       transaction.savepoint_commit(sid)
    except Exception, e:
       if isinstance(e, IntegrityError):
           transaction.savepoint_rollback(sid)
           print "Pass"
       else:
           print "Fail with %s" % type(e)
Expected:
    Pass
Got:
    Fail with <class 'psycopg.ProgrammingError'>
----------------------------------------------------------------------

comment:3 Changed 6 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 5 years ago by thejaswi_puthraya

Heh, I can't replicate a similar error on #12171 with the psycopg1 backend but this can be. Here is the complete error that I get...

F
======================================================================
FAIL: Doctest: custom_pk.models.__test__.API_TESTS
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/theju/trunk/django/test/_doctest.py", line 2180, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for custom_pk.models.__test__.API_TESTS
  File "/home/theju/abcd/custom_pk/models.py", line unknown line number, in API_TESTS

----------------------------------------------------------------------
File "/home/theju/abcd/custom_pk/models.py", line ?, in custom_pk.models.__test__.API_TESTS
Failed example:
    try:
       sid = transaction.savepoint()
       Employee.objects.create(employee_code=123, first_name='Fred', last_name='Jones')
       transaction.savepoint_commit(sid)
    except Exception, e:
       if isinstance(e, IntegrityError):
           transaction.savepoint_rollback(sid)
           print "Pass"
       else:
           print "Fail with %s" % type(e)
Exception raised:
    Traceback (most recent call last):
      File "/home/theju/trunk/django/test/_doctest.py", line 1267, in __run
        compileflags, 1) in test.globs
      File "<doctest custom_pk.models.__test__.API_TESTS[35]>", line 7, in <module>
        transaction.savepoint_rollback(sid)
      File "/home/theju/trunk/django/db/transaction.py", line 242, in savepoint_rollback
        connection._savepoint_rollback(sid)
      File "/home/theju/trunk/django/db/backends/__init__.py", line 61, in _savepoint_rollback
        self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
      File "/home/theju/trunk/django/db/backends/__init__.py", line 75, in cursor
        cursor = self._cursor()
      File "/home/theju/trunk/django/db/backends/postgresql/base.py", line 149, in _cursor
        cursor.execute("SET client_encoding to 'UNICODE'")
    ProgrammingError: ERROR:  current transaction is aborted, commands ignored until end of transaction block

    SET client_encoding to 'UNICODE'
----------------------------------------------------------------------
File "/home/theju/abcd/custom_pk/models.py", line ?, in custom_pk.models.__test__.API_TESTS
Failed example:
    try:
        sid = transaction.savepoint()
        Employee.objects.create(first_name='Tom', last_name='Smith')
        print 'hello'
        transaction.savepoint_commit(sid)
        print 'hello2'
    except Exception, e:
        if isinstance(e, IntegrityError):
            transaction.savepoint_rollback(sid)
            print "Pass"
        else:
            print "Fail with %s" % type(e)
Exception raised:
    Traceback (most recent call last):
      File "/home/theju/trunk/django/test/_doctest.py", line 1267, in __run
        compileflags, 1) in test.globs
      File "<doctest custom_pk.models.__test__.API_TESTS[41]>", line 9, in <module>
        transaction.savepoint_rollback(sid)
      File "/home/theju/trunk/django/db/transaction.py", line 242, in savepoint_rollback
        connection._savepoint_rollback(sid)
      File "/home/theju/trunk/django/db/backends/__init__.py", line 61, in _savepoint_rollback
        self.cursor().execute(self.ops.savepoint_rollback_sql(sid))
      File "/home/theju/trunk/django/db/backends/__init__.py", line 75, in cursor
        cursor = self._cursor()
      File "/home/theju/trunk/django/db/backends/postgresql/base.py", line 149, in _cursor
        cursor.execute("SET client_encoding to 'UNICODE'")
    ProgrammingError: ERROR:  current transaction is aborted, commands ignored until end of transaction block

    SET client_encoding to 'UNICODE'


----------------------------------------------------------------------
Ran 1 test in 0.223s

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

comment:5 Changed 5 years ago by russellm

These test fail under 1.1 as well, so this is something that has been broken for a while.

comment:6 Changed 5 years ago by russellm

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

(In [12848]) Fixed #12766 -- Only set the psycopg1 client encoding when the connection is first created. This allows the custom_pk test to pass under psycopg1.

comment:7 Changed 5 years ago by russellm

(In [12849]) [1.1.X] Fixed #12766 -- Only set the psycopg1 client encoding when the connection is first created. This allows the custom_pk test to pass under psycopg1.

Backport of r12848 from trunk.

comment:8 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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