Edgewall Software
Modify

Opened 8 years ago

Closed 8 years ago

#12622 closed defect (fixed)

trac.tests.env.SystemInfoTestCase failure with PostgreSQL on Windows

Reported by: Christian Boos Owned by: Jun Omae
Priority: normal Milestone: 1.3.1
Component: database backend Version:
Severity: minor Keywords:
Cc: Branch:
Release Notes:

Load libpq library to call libpq_version only if it is dynamically linked.

API Changes:
Internal Changes:

Description

 Psycopg2     : 2.6.1 (dt dec pq3 ext lo64)
...
 PostgreSQL version    : psql (PostgreSQL) 9.1.1
FAIL: test_database_backend_version (trac.tests.env.SystemInfoTestCase)
Database backend is returned in system_info.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\Trac\repos\trunk\trac\tests\env.py", line 311, in test_database_backend_version
    r'^server: \(not-connected\), '
AssertionError: Regexp didn't match: '^server: \\(not-connected\\), client: \\d+(\\.\\d+)+$' not found in 'server: (not-connected), client: (unknown)'

1.2-stable is not affected as the test exists only in trunk.

Attachments (0)

Change History (8)

comment:1 by Christian Boos, 8 years ago

The code trunk/trac/db/postgres_backend.py@15152:287#L281 falls back to "(unknown)" because it tries to CDLL load a 32-bit PostgreSQL libpq.dll from a 64-bit Python.

A more robust approach might be to get the File Version attribute of the .dll (à la SO:580924/python-windows-file-version-attribute).

In the meantime, the following should do:

  • trac/tests/env.py

     
    309309        elif self.env.dburi.startswith('postgres'):
    310310            self.assertRegexpMatches(get_info(info_before, 'PostgreSQL'),
    311311                                     r'^server: \(not-connected\), '
    312                                      r'client: \d+(\.\d+)+$')
     312                                     r'client: (\d+(\.\d+)+|\(unknown\))$')
    313313            self.assertRegexpMatches(get_info(info_after, 'PostgreSQL'),
    314314                                     r'^server: \d+(\.\d+)+, '
    315                                      r'client: \d+(\.\d+)+$')
     315                                     r'client: (\d+(\.\d+)+|\(unknown\))$')
    316316            self.assertRegexpMatches(get_info(info_before, 'psycopg2'),
    317317                                     r'^\d+(\.\d+)+$')
    318318            self.assertRegexpMatches(get_info(info_after, 'psycopg2'),
Last edited 8 years ago by Christian Boos (previous) (diff)

comment:2 by Christian Boos, 8 years ago

Got a similar one on Linux for MySQL (MariaDB actually):

FAIL: test_database_backend_version (trac.tests.env.SystemInfoTestCase)
Database backend is returned in system_info.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/cboos/trac/trunk/trac/tests/env.py", line 300, in test_database_backend_version
    r'^server: \(not-connected\), '
AssertionError: Regexp didn't match: '^server: \\(not-connected\\), client: "\\d+(\\.\\d+)+", thread-safe: 1$' not found in 'server: (not-connected), client: "10.0.21-MariaDB", thread-safe: 1'

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

in reply to:  1 ; comment:3 by Jun Omae, 8 years ago

Replying to Christian Boos:

The code trunk/trac/db/postgres_backend.py@15152:287#L281 falls back to "(unknown)" because it tries to CDLL load a 32-bit PostgreSQL libpq.dll from a 64-bit Python.

Are you using win-psycopg? It seems the win-psycopg is built using static libraries of PostgreSQL libpq 9.5.3. I reconsider we shouldn't try to load libpq.dll if it is unable to detect that is static linking or dynamic linking.

in reply to:  3 comment:4 by Christian Boos, 8 years ago

Replying to Jun Omae:

Replying to Christian Boos:

The code trunk/trac/db/postgres_backend.py@15152:287#L281 falls back to "(unknown)" because it tries to CDLL load a 32-bit PostgreSQL libpq.dll from a 64-bit Python.

Are you using win-psycopg?

Yes, I think so, as that's the official port of psycopg2 for Windows. The lib/site-packages/psycopg2/_psycopg.pyd library indeed doesn't depend on libpq.dll.

comment:5 by Jun Omae, 8 years ago

Proposed changes in [f68e43418/jomae.git]. If name of shared library is found in contents of psycopyg2._psycopg.__file__, try to load.

Linux:

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.test import EnvironmentStub
>>> env = EnvironmentStub()
>>> for _ in env.get_systeminfo(): _
...
('Babel', '2.3.4')
('Genshi', '0.6 (with speedups)')
('PostgreSQL', 'server: 9.1.20, client: 9.3.14')
('psycopg2', '2.6.2')
>>> from trac.db.postgres_backend import _libpq_pathname
>>> _libpq_pathname
'libpq.so.5'

Mac OS X:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.test import EnvironmentStub
>>> env = EnvironmentStub()
>>> for _ in env.get_systeminfo(): _
...
('Genshi', '0.6 (without speedups)')
('PostgreSQL', 'server: 9.1.20, client: 9.6.1')
('psycopg2', '2.6.2')
>>> from trac.db.postgres_backend import _libpq_pathname
>>> _libpq_pathname
'/usr/local/opt/postgresql/lib/libpq.5.dylib'

Windows: untested

comment:6 by Christian Boos, 8 years ago

Windows:

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.test import EnvironmentStub
>>> env = EnvironmentStub()
>>> for _ in env.get_systeminfo(): _
...
('Babel', '2.1.1')
('Genshi', '0.7 (with speedups)')
('PostgreSQL', 'server: 9.1.1, client: (unknown)')
('psycopg2', '2.6.1')

And the unit-tests pass on both problematic platforms. Thanks for the fix!

comment:7 by Jun Omae, 8 years ago

Owner: changed from Christian Boos to Jun Omae

comment:8 by Jun Omae, 8 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Thanks for the testing! Committed in [15257].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Jun Omae to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.