Opened 9 years ago

Closed 9 years ago

#23807 closed Bug (fixed)

Postgres backend throws error when coercing psycopg2 version string to int when version contains non-numeric characters

Reported by: Ryan Bagwell Owned by: Andriy Sokolovskiy
Component: Database layer (models, ORM) Version: dev
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

The postgres backend that ships with Django expects the version string of psycopg2 to contain numeric characters. It then tries to coerce the string to a tuple, i.e. (2, 5, 4,) for '2.5.4'. This throws an error when using the development branch, which has a version string of '2.6.dev0' (you can't coerce "dev0" to a string.

The problem method is located here:

https://github.com/django/django/blob/master/django/db/backends/postgresql_psycopg2/base.py#L202

@cached_property
def psycopg2_version(self):
    version = psycopg2.__version__.split(' ', 1)[0]
    return tuple(int(v) for v in version.split('.'))

This was a problem for me due to a bug in psycopg2 that was fixed in the dev branch but not in the most recent release.

I don't know how best to address it. Do other applications expect the version tuple to consist entirely of integers?

Change History (3)

comment:1 by Tim Graham, 9 years ago

Triage Stage: UnreviewedAccepted
Version: 1.7master

It seems like a reasonable request. You could look at the strategies use by other database backends in Django (regular expressions in MySQL, for example). It might also be fine simply to discard the value that can't be parsed.

comment:2 by Andriy Sokolovskiy, 9 years ago

Owner: changed from nobody to Andriy Sokolovskiy
Status: newassigned

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 1739ae9edc6e6c07ca20cad36dd15316f18f3f8e:

Fixed #23807 -- Ignored non-digits in psycopg2 version

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