Skip to content

Commit 1fa12fe

Browse files
committed
Parse server version x.y as x.0.y, when x is >= 10
Since PostgreSQL 10 the versioning scheme has changed. 10.x really means 10.0.x. While parsing 10.1 as (10, 1) may seem less confusing, in practice most version checks are written as version[:2], and we want to keep that behaviour consistent, i.e not fail a major version check due to a bugfix release.
1 parent afc1038 commit 1fa12fe

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

asyncpg/serverversion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def split_server_version_string(version_string):
3434
level = 'final'
3535
serial = 0
3636

37+
if int(parts[0]) >= 10:
38+
# Since PostgreSQL 10 the versioning scheme has changed.
39+
# 10.x really means 10.0.x. While parsing 10.1
40+
# as (10, 1) may seem less confusing, in practice most
41+
# version checks are written as version[:2], and we
42+
# want to keep that behaviour consistent, i.e not fail
43+
# a major version check due to a bugfix release.
44+
parts.insert(1, 0)
45+
3746
versions = [int(p) for p in parts][:3]
3847
if len(versions) < 3:
3948
versions += [0] * (3 - len(versions))

tests/test_connect.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ def test_server_version_02(self):
5353
("9.4beta1", (9, 4, 0, 'beta', 1),),
5454
("10devel", (10, 0, 0, 'devel', 0),),
5555
("10beta2", (10, 0, 0, 'beta', 2),),
56-
57-
# Despite the fact after version 10 Postgre's second number
58-
# means "micro", it is parsed "as is" to be
59-
# less confusing in comparisons.
60-
("10.1", (10, 1, 0, 'final', 0),),
56+
# For PostgreSQL versions >=10 we always
57+
# set version.minor to 0.
58+
("10.1", (10, 0, 1, 'final', 0),),
59+
("11.1.2", (11, 0, 1, 'final', 0),),
6160
]
6261
for version, expected in versions:
6362
result = split_server_version_string(version)

0 commit comments

Comments
 (0)