Skip to content

Fix server version parsing when it contains trailing data #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion asyncpg/serverversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def split_server_version_string(version_string):
if version_string.startswith('PostgreSQL '):
version_string = version_string[len('PostgreSQL '):]
if version_string.startswith('Postgres-XL'):
version_string = version_string[len('Postgre-XL '):]
version_string = version_string[len('Postgres-XL '):]

# Some distros (e.g Debian) like may inject their branding
# into the numeric version string, so make sure to only look
# at stuff before the first space.
version_string = version_string.split(' ')[0]
parts = version_string.strip().split('.')
if not parts[-1].isdigit():
# release level specified
Expand Down
3 changes: 2 additions & 1 deletion tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ async def test_server_version_01(self):
def test_server_version_02(self):
versions = [
("9.2", (9, 2, 0, 'final', 0),),
("9.2.1", (9, 2, 1, 'final', 0),),
("Postgres-XL 9.2.1", (9, 2, 1, 'final', 0),),
("9.4beta1", (9, 4, 0, 'beta', 1),),
("10devel", (10, 0, 0, 'devel', 0),),
("10beta2", (10, 0, 0, 'beta', 2),),
# For PostgreSQL versions >=10 we always
# set version.minor to 0.
("10.1", (10, 0, 1, 'final', 0),),
("11.1.2", (11, 0, 1, 'final', 0),),
("PostgreSQL 10.1 (Debian 10.1-3)", (10, 0, 1, 'final', 0),),
]
for version, expected in versions:
result = split_server_version_string(version)
Expand Down