summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-03-01 13:17:34 -0500
committerTim Graham <timograham@gmail.com>2017-03-01 13:17:34 -0500
commit29ea9714ee23525000dd8bdb7a9aafb2147de8c7 (patch)
treef2d2217735ac8b769449684a8303a63a7e9833c6
parent49a63d08d3b3e2ac32e391d1413a4ac99429e4af (diff)
Removed PostgreSQL version detection for psycopg2 < 2.0.12.
-rw-r--r--django/db/backends/postgresql/base.py3
-rw-r--r--django/db/backends/postgresql/version.py44
-rw-r--r--tests/backends/tests.py44
3 files changed, 1 insertions, 90 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index f8a13eeb5f..0703e19098 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -42,7 +42,6 @@ from .introspection import DatabaseIntrospection # NOQA isort:skip
from .operations import DatabaseOperations # NOQA isort:skip
from .schema import DatabaseSchemaEditor # NOQA isort:skip
from .utils import utc_tzinfo_factory # NOQA isort:skip
-from .version import get_version # NOQA isort:skip
psycopg2.extensions.register_adapter(SafeText, psycopg2.extensions.QuotedString)
psycopg2.extras.register_uuid()
@@ -274,4 +273,4 @@ class DatabaseWrapper(BaseDatabaseWrapper):
@cached_property
def pg_version(self):
with self.temporary_connection():
- return get_version(self.connection)
+ return self.connection.server_version
diff --git a/django/db/backends/postgresql/version.py b/django/db/backends/postgresql/version.py
deleted file mode 100644
index 3b219159f5..0000000000
--- a/django/db/backends/postgresql/version.py
+++ /dev/null
@@ -1,44 +0,0 @@
-"""
-Extract the version of the PostgreSQL server.
-"""
-
-import re
-
-# This reg-exp is intentionally fairly flexible here.
-# Needs to be able to handle stuff like:
-# PostgreSQL #.#.#
-# EnterpriseDB #.#
-# PostgreSQL #.# beta#
-# PostgreSQL #.#beta#
-VERSION_RE = re.compile(r'\S+ (\d+)\.(\d+)\.?(\d+)?')
-
-
-def _parse_version(text):
- "Internal parsing method. Factored out for testing purposes."
- major, major2, minor = VERSION_RE.search(text).groups()
- try:
- return int(major) * 10000 + int(major2) * 100 + int(minor)
- except (ValueError, TypeError):
- return int(major) * 10000 + int(major2) * 100
-
-
-def get_version(connection):
- """
- Return an integer representing the major, minor, and revision number of the
- server. Format is the one used for the return value of libpq
- PQServerVersion()/``server_version`` connection attribute (available in
- newer psycopg2 versions.)
-
- For example, 90304 for 9.3.4. The last two digits will be 00 in the case of
- releases (e.g., 90400 for 'PostgreSQL 9.4') or in the case of beta and
- prereleases (e.g. 90100 for 'PostgreSQL 9.1beta2').
-
- PQServerVersion()/``server_version`` doesn't execute a query so try that
- first, then fallback to a ``SELECT version()`` query.
- """
- if hasattr(connection, 'server_version'):
- return connection.server_version
- else:
- with connection.cursor() as cursor:
- cursor.execute("SELECT version()")
- return _parse_version(cursor.fetchone()[0])
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 460b35084a..7853d02a24 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -14,7 +14,6 @@ from django.db import (
reset_queries, transaction,
)
from django.db.backends.base.base import BaseDatabaseWrapper
-from django.db.backends.postgresql import version as pg_version
from django.db.backends.signals import connection_created
from django.db.backends.utils import CursorWrapper, format_number
from django.db.models import Avg, StdDev, Sum, Variance
@@ -190,22 +189,6 @@ class SQLiteTests(TestCase):
@unittest.skipUnless(connection.vendor == 'postgresql', "Test only for PostgreSQL")
class PostgreSQLTests(TestCase):
- def assert_parses(self, version_string, version):
- self.assertEqual(pg_version._parse_version(version_string), version)
-
- def test_parsing(self):
- """Test PostgreSQL version parsing from `SELECT version()` output"""
- self.assert_parses("PostgreSQL 9.3 beta4", 90300)
- self.assert_parses("PostgreSQL 9.3", 90300)
- self.assert_parses("EnterpriseDB 9.3", 90300)
- self.assert_parses("PostgreSQL 9.3.6", 90306)
- self.assert_parses("PostgreSQL 9.4beta1", 90400)
- self.assert_parses(
- "PostgreSQL 9.3.1 on i386-apple-darwin9.2.2, compiled by GCC "
- "i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5478)",
- 90301
- )
-
def test_nodb_connection(self):
"""
The _nodb_connection property fallbacks to the default connection
@@ -231,33 +214,6 @@ class PostgreSQLTests(TestCase):
self.assertEqual(len(w), 1)
self.assertEqual(w[0].message.__class__, RuntimeWarning)
- def test_version_detection(self):
- """Test PostgreSQL version detection"""
-
- # Helper mocks
- class CursorMock:
- "Very simple mock of DB-API cursor"
- def execute(self, arg):
- pass
-
- def fetchone(self):
- return ["PostgreSQL 9.3"]
-
- def __enter__(self):
- return self
-
- def __exit__(self, type, value, traceback):
- pass
-
- class OlderConnectionMock:
- "Mock of psycopg2 (< 2.0.12) connection"
- def cursor(self):
- return CursorMock()
-
- # psycopg2 < 2.0.12 code path
- conn = OlderConnectionMock()
- self.assertEqual(pg_version.get_version(conn), 90300)
-
def test_connect_and_rollback(self):
"""
PostgreSQL shouldn't roll back SET TIME ZONE, even if the first