AttributeError when running test against PostgreSql 8.4beta1

9 views
Skip to first unread message

Horacio de Oro

unread,
Apr 15, 2009, 8:48:50 PM4/15/09
to Django developers
Hi!
I get an AttributeError while trying PostgreSql 8.4beta1 (compiled
from 'master' branch of the official git repository). See:

python2.4 src/dynamicware/manage.py test xx.FeedRetrieverServiceTest
Creating test database...
Traceback (most recent call last):
File "src/dynamicware/manage.py", line 35, in ?
execute_manager(settings)
File "/path/to/project/Django-1.0.2/django/core/management/
__init__.py", line 340, in execute_manager
utility.execute()
File "/path/to/project/Django-1.0.2/django/core/management/
__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/path/to/project/Django-1.0.2/django/core/management/base.py",
line 192, in run_from_argv
self.execute(*args, **options.__dict__)
File "/path/to/project/Django-1.0.2/django/core/management/base.py",
line 219, in execute
output = self.handle(*args, **options)
File "/path/to/project/Django-1.0.2/django/core/management/commands/
test.py", line 33, in handle
failures = test_runner(test_labels, verbosity=verbosity,
interactive=interactive)
File "/path/to/project/Django-1.0.2/django/test/simple.py", line
142, in run_tests
connection.creation.create_test_db(verbosity, autoclobber=not
interactive)
File "/path/to/project/Django-1.0.2/django/db/backends/creation.py",
line 310, in create_test_db
test_database_name = self._create_test_db(verbosity, autoclobber)
File "/path/to/project/Django-1.0.2/django/db/backends/creation.py",
line 341, in _create_test_db
cursor = self.connection.cursor()
File "/path/to/project/Django-1.0.2/django/db/backends/__init__.py",
line 56, in cursor
cursor = self._cursor(settings)
File "/path/to/project/Django-1.0.2/django/db/backends/
postgresql_psycopg2/base.py", line 92, in _cursor
self.__class__._version = get_version(cursor)
File "/path/to/project/Django-1.0.2/django/db/backends/postgresql/
version.py", line 19, in get_version
major, minor = VERSION_RE.search(version).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

The devserver works ok.

I think I've tracked down the problem: the RE used to get the version
of PostgreSql. On django/db/backends/postgresql/version.py:
VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')

So, PostgreSQL 8.3 (Ubuntu 8.10) returns this version string:
"PostgreSQL 8.3.7 on i486-pc-linux-gnu, compiled by GCC gcc-4.3.real
(Ubuntu 4.3.2-1ubuntu11) 4.3.2"

But PostgreSql 8.4beta1 returns:
"PostgreSQL 8.4beta1 on i686-pc-linux-gnu, compiled by GCC gcc (Ubuntu
4.3.2-1ubuntu12) 4.3.2, 32-bit"

With the folowing VERSION_RE the test worked OK with PGSQL 8.3 and
8.4beta:

VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\D')

Is this a bug? Should I file a bug report?
I hope you find this helpfull. Sory for my English and thanks in
advance!

Horacio

(this is the diff against Django-1.0.2)

--- a/Django-1.0.2/django/db/backends/postgresql/version.py
+++ b/Django-1.0.2/django/db/backends/postgresql/version.py
@@ -4,7 +4,7 @@ Extracts the version of the PostgreSQL server.

import re

-VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')
+VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\D')

def get_version(cursor):
"""

Jacob Kaplan-Moss

unread,
Apr 15, 2009, 8:53:54 PM4/15/09
to django-d...@googlegroups.com
On Wed, Apr 15, 2009 at 7:48 PM, Horacio de Oro <hgd...@gmail.com> wrote:
> Is this a bug? Should I file a bug report?

Yes, please do. Thanks!

Jacob

Horacio de Oro

unread,
Apr 15, 2009, 11:14:40 PM4/15/09
to Django developers
On Apr 15, 9:53 pm, Jacob Kaplan-Moss <jacob.kaplanm...@gmail.com>
wrote:
> On Wed, Apr 15, 2009 at 7:48 PM, Horacio de Oro <hgde...@gmail.com> wrote:
>
> > Is this a bug? Should I file a bug report?
>
> Yes, please do. Thanks!
>
> Jacob

Testing with another applicatoin, I've found that
"request.user.is_authenticated()" produces the same exception on the
development web server (with Django 1.0.2).
Anyway, I've checked out the code from the git repository and and I've
found duplicated the code that get the postgrsql version in:

django/db/backends/postgresql/version.py (Django 1.1-dev)
VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)')

and:

django/db/backends/postgresql/operations.py (Django 1.1-dev)
server_version_re = re.compile(r'PostgreSQL (\d{1,2})\.(\d{1,2})\.?(\d
{1,2})?')

I've found some bug reports related to this (#6433, #8737, #9953), and
the the ticket #8737 says:
"PostgreSQL version detection is fragile; no longer works for
EnterpriseDB"

I think that it should be re-opened and at least change
server_version_re = re.compile(r'PostgreSQL (\d{1,2})\.(\d{1,2})\.?(\d
{1,2})?')

with:

server_version_re = re.compile(r'\S+ (\d{1,2})\.(\d{1,2})\.?(\d
{1,2})?')
This way, EnterpriseDB should works fine (this should be changed in
1.0.2 and 1.1-dev).

Maybe #6433 ("postgres backend doesn't accept version number 8.3RC2")
should be reopened, and apply this fixes on Django 1.0.2:

- In django/db/backends/postgresql/version.py, change
VERSION_RE = re.compile(r'PostgreSQL (\d+)\.(\d+)\.')

with the RE of current trunk:

VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)')

If you agree, I'd be glad to re-open those thickets, upload the
patches or both things.

Horacio

Russell Keith-Magee

unread,
Apr 15, 2009, 11:25:29 PM4/15/09
to django-d...@googlegroups.com

Thanks for the detail, Horacio.

Open a new ticket, rather than reopening old ones. Those tickets were
acurately closed at the time; this is new issue. For the sake of
completeness, if you could include the actual string that needs to be
matched, it would be helpful. That way, if we have a similar bug in
the future, we can make a note of the list of patterns that need to be
matched.

Yours
Russ Magee %-)

Horacio de Oro

unread,
Apr 16, 2009, 1:29:00 PM4/16/09
to Django developers
Done. http://code.djangoproject.com/ticket/10842

Thanks!!!
Horacio

On Apr 16, 12:25 am, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages