[Django] #23807: Postgres backend throws error when coercing psycopg2 version string to int when version contains non-numeric characters

19 views
Skip to first unread message

Django

unread,
Nov 12, 2014, 2:55:45 PM11/12/14
to django-...@googlegroups.com
#23807: Postgres backend throws error when coercing psycopg2 version string to int
when version contains non-numeric characters
----------------------------------------------+--------------------
Reporter: ryanbagwell | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.7
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/23807>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 13, 2014, 5:23:44 AM11/13/14
to django-...@googlegroups.com
#23807: Postgres backend throws error when coercing psycopg2 version string to int
when version contains non-numeric characters
-------------------------------------+-------------------------------------

Reporter: ryanbagwell | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_docs: => 0
* needs_better_patch: => 0
* version: 1.7 => master
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/23807#comment:1>

Django

unread,
Nov 29, 2014, 9:12:41 AM11/29/14
to django-...@googlegroups.com
#23807: Postgres backend throws error when coercing psycopg2 version string to int
when version contains non-numeric characters
-------------------------------------+-------------------------------------
Reporter: ryanbagwell | Owner: coldmind
Type: Bug | Status: assigned

Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by coldmind):

* owner: nobody => coldmind
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/23807#comment:2>

Django

unread,
Dec 1, 2014, 6:43:07 PM12/1/14
to django-...@googlegroups.com
#23807: Postgres backend throws error when coercing psycopg2 version string to int
when version contains non-numeric characters
-------------------------------------+-------------------------------------
Reporter: ryanbagwell | Owner: coldmind
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) | Resolution: fixed

Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"1739ae9edc6e6c07ca20cad36dd15316f18f3f8e"]:
{{{
#!CommitTicketReference repository=""
revision="1739ae9edc6e6c07ca20cad36dd15316f18f3f8e"
Fixed #23807 -- Ignored non-digits in psycopg2 version
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/23807#comment:3>

Reply all
Reply to author
Forward
0 new messages