Edgewall Software

Opened 5 years ago

Last modified 5 years ago

#13160 closed defect

Unit tests failing when psycopg2 2.8.x due to raising `UniqueViolation` instead of `IntegrityError` — at Version 8

Reported by: Jun Omae Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.19
Component: general Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed unit test failures with psycopg2 2.8.x.

API Changes:
Internal Changes:

Description

https://travis-ci.org/edgewall/trac/jobs/521140057

======================================================================
FAIL: test_component_add_error_already_exists (trac.admin.tests.console.TracadminTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/edgewall/trac/trac/admin/tests/console.py", line 541, in test_component_add_error_already_exists
    self.assertExpectedResult(output)
  File "/home/travis/build/edgewall/trac/trac/admin/tests/console.py", line 172, in assertExpectedResult
    self.assertEqual(expected_result, output)
  File "/home/travis/build/edgewall/trac/trac/admin/tests/console.py", line 194, in assertEqual
    output, diff()))
AssertionError: u'IntegrityError: [...]\n' != u'UniqueViolation: duplicate key value violates unique constraint "component_pkey"\nDETAIL:  Key (name)=(component1) already exists.\n\n'
--- expected
+++ actual
@@ -1,2 +1,4 @@
-IntegrityError: [...]
+UniqueViolation: duplicate key value violates unique constraint "component_pkey"
+DETAIL:  Key (name)=(component1) already exists.
 
+
...

----------------------------------------------------------------------
Ran 1958 tests in 132.317s

FAILED (failures=10)
make: *** [unit-test] Error 1

Change History (8)

comment:1 by Jun Omae, 5 years ago

The UniqueViolation exception is inherited from IntegrityError and not exported.

>>> import psycopg2
>>> psycopg2.__version__
'2.8.2 (dt dec pq3 ext lo64)'
>>> from psycopg2 import UniqueViolation
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name UniqueViolation
>>> from psycopg2._psycopg import sqlstate_errors
>>> sqlstate_errors['23505']
<class 'psycopg2.errors.UniqueViolation'>
>>> sqlstate_errors['23505'].__bases__
(<class 'psycopg2.IntegrityError'>,)
>>> issubclass(sqlstate_errors['23505'], psycopg2.IntegrityError)
True

comment:2 by Jun Omae, 5 years ago

Ad hoc patch is pinning psycopg2<2.8.

  • .travis.yml

    diff --git a/.travis.yml b/.travis.yml
    index 8fc1192e8..860026e63 100644
    a b install:  
    103103      2.6) requires="$requires Babel<2.6.0 lxml<4.3.0" ;;
    104104      *)   requires="$requires Babel lxml" ;;
    105105    esac
    106     if [ "$tracdb" = postgres ]; then requires="$requires psycopg2"; fi
     106    if [ "$tracdb" = postgres ]; then requires="$requires psycopg2<2.8"; fi
    107107    if [ "$tracdb" = mysql ]; then requires="$requires MySQL-python"; fi
    108108    pip install $requires
    109109    python -c 'import sys, pkg_resources as p; p.require(sys.argv[1:])' $requires
  • contrib/appveyor.ps1

    diff --git a/contrib/appveyor.ps1 b/contrib/appveyor.ps1
    index af5a3b867..a6bac3ff2 100644
    a b function Trac-Install {  
    254254        # "postgres://tracuser:password@localhost/trac?schema=tractest"
    255255        #
    256256
    257         & pip install psycopg2
     257        & pip install psycopg2<2.8
    258258
    259259        Add-AppveyorMessage -Message "1.1. psycopg2 package installed" `
    260260          -Category Information

comment:3 by Ryan J Ollos, 5 years ago

The workaround looks good to get our build passing again.

Once that is committed I'll do some testing on a branch with Ubuntu Xenial, which is being rolled out.

comment:4 by Jun Omae, 5 years ago

I noticed the unit tests on trunk pass with psycopg2 2.8.2 at https://travis-ci.org/edgewall/trac/jobs/521143761#L708. The tests which try to insert non-unique ticket property have been removed in r15380….

in reply to:  4 comment:5 by Jun Omae, 5 years ago

Replying to Jun Omae:

I noticed the unit tests on trunk pass with psycopg2 2.8.2 at https://travis-ci.org/edgewall/trac/jobs/521143761#L708. The tests which try to insert non-unique ticket property have been removed in r15380….

ResourceExistsError is raised on trunk in the case and the tests exist in trac/ticket/tests/console-tests.txt.

comment:6 by Ryan J Ollos, 5 years ago

I committed the comment:2 workaround in r16906, r16907, record-only merge in r16908.

comment:7 by Ryan J Ollos, 5 years ago

Milestone: 1.0.181.0.19

comment:8 by Ryan J Ollos, 5 years ago

Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned
Note: See TracTickets for help on using tickets.