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

This commit is contained in:
Andriy Sokolovskiy 2014-11-29 16:36:36 +02:00 committed by Tim Graham
parent b8cc5f3cd4
commit 1739ae9edc
2 changed files with 12 additions and 2 deletions

View File

@ -216,7 +216,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
@cached_property @cached_property
def psycopg2_version(self): def psycopg2_version(self):
version = psycopg2.__version__.split(' ', 1)[0] version = psycopg2.__version__.split(' ', 1)[0]
return tuple(int(v) for v in version.split('.')) return tuple(int(v) for v in version.split('.') if v.isdigit())
@cached_property @cached_property
def pg_version(self): def pg_version(self):

View File

@ -22,7 +22,7 @@ from django.db.backends.utils import format_number, CursorWrapper
from django.db.models import Sum, Avg, Variance, StdDev from django.db.models import Sum, Avg, Variance, StdDev
from django.db.models.sql.constants import CURSOR from django.db.models.sql.constants import CURSOR
from django.db.utils import ConnectionHandler from django.db.utils import ConnectionHandler
from django.test import (TestCase, TransactionTestCase, override_settings, from django.test import (TestCase, TransactionTestCase, mock, override_settings,
skipUnlessDBFeature, skipIfDBFeature) skipUnlessDBFeature, skipIfDBFeature)
from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin
from django.utils import six from django.utils import six
@ -246,6 +246,16 @@ class PostgreSQLTests(TestCase):
'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'): 'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'):
self.assertIn('::text', do.lookup_cast(lookup)) self.assertIn('::text', do.lookup_cast(lookup))
def test_correct_extraction_psycopg2_version(self):
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper
version_path = 'django.db.backends.postgresql_psycopg2.base.Database.__version__'
with mock.patch(version_path, '2.6.9'):
self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 6, 9))
with mock.patch(version_path, '2.5.dev0'):
self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 5))
class DateQuotingTest(TestCase): class DateQuotingTest(TestCase):