Opened 11 months ago

Closed 7 months ago

#27830 closed Bug (fixed)

Use distutils.version.LooseVersion instead of custom version parsing

Reported by: NotSqrt Owned by: ChillarAnand
Component: Core (Other) Version: 1.10
Severity: Normal Keywords:
Cc: anand21nanda@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Hi !

As discussed with Tim Graham in https://groups.google.com/forum/#!topic/django-users/BM3d679AsyA

django/db/backends/postgresql_psycopg2/base.py:psycopg2_version can't handle versions like 2.7b1 or 2.7b2.dev0(the current git versions), because it only returns (2, ), which is lower than the minimal requirement of (2, 4, 5).

A possibility is to use :

  from distutils.version import LooseVersion
  LooseVersion(psycopg2.__version__.split(' ', 1)[0]) >= LooseVersion('2.4.5')

Another possibility is packaging, the reference implementation of PEP-440, which is a dependency of setuptools (previously included in its vendor libs), so very probably installed everywhere !

While searching for "version" in the django code base, there appears to be multiple regex used to parse version strings : mysql, postgresql, gdal, geos.
This could probably be more DRY, and correct.

I've seen things like if geos_version_info()['version'] < '3.3.0':, which might fail at some point.

Thanks !

Change History (8)

comment:1 Changed 11 months ago by Tim Graham

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:2 Changed 11 months ago by ChillarAnand

Owner: changed from nobody to ChillarAnand
Status: newassigned

comment:3 Changed 11 months ago by ChillarAnand

Cc: anand21nanda@… added
Has patch: set

Fixed in PR

comment:4 Changed 11 months ago by Tim Graham

Patch needs improvement: set

Additional tests are needed.

comment:5 Changed 10 months ago by ChillarAnand

Added additional test cases.

comment:6 Changed 8 months ago by Tim Graham

I'm doubtful that packaging is always available. I created a Python 3.6.1 virtualenv and can import setuptools ('36.0.1') but not packaging.

comment:7 Changed 8 months ago by ChillarAnand

Good catch. Replaced it with distutils.version.LooseVersion.

comment:8 Changed 7 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 08bda82c:

Fixed #27830 -- Used distutils.version.LooseVersion for version parsing.

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