Skip to content

Commit 32858c0

Browse files
patchback[bot]rgl
andauthored
fix: only parse the digits from the pg version (#315) (#316) (#321)
(cherry picked from commit e1562dc) Co-authored-by: Rui Lopes <[email protected]>
1 parent d6ffb54 commit 32858c0

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bugfixes:
2+
- postgresql_ping - fix pg version parsing (https://github.com/ansible-collections/community.postgresql/issues/315).
3+
- postgresql_info - fix pg version parsing (https://github.com/ansible-collections/community.postgresql/issues/315).

plugins/modules/postgresql_info.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@
506506
sample: false
507507
'''
508508

509+
import re
509510
from fnmatch import fnmatch
510511

511512
try:
@@ -956,13 +957,13 @@ def get_pg_version(self):
956957
query = "SELECT version()"
957958
raw = self.__exec_sql(query)[0][0]
958959
full = raw.split()[1]
959-
tmp = full.split('.')
960+
m = re.match(r"(\d+)\.(\d+)(?:\.(\d+))?", full)
960961

961-
major = int(tmp[0])
962-
minor = int(tmp[1].rstrip(','))
962+
major = int(m.group(1))
963+
minor = int(m.group(2))
963964
patch = None
964-
if len(tmp) >= 3:
965-
patch = int(tmp[2].rstrip(','))
965+
if m.group(3) is not None:
966+
patch = int(m.group(3))
966967

967968
self.pg_info["version"] = dict(
968969
major=major,

plugins/modules/postgresql_ping.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
version_added: 1.7.0
9292
'''
9393

94+
import re
95+
9496
try:
9597
from psycopg2.extras import DictCursor
9698
except ImportError:
@@ -136,13 +138,13 @@ def get_pg_version(self):
136138
self.is_available = True
137139

138140
full = raw.split()[1]
139-
tmp = full.split('.')
141+
m = re.match(r"(\d+)\.(\d+)(?:\.(\d+))?", full)
140142

141-
major = int(tmp[0])
142-
minor = int(tmp[1].rstrip(','))
143+
major = int(m.group(1))
144+
minor = int(m.group(2))
143145
patch = None
144-
if len(tmp) >= 3:
145-
patch = int(tmp[2].rstrip(','))
146+
if m.group(3) is not None:
147+
patch = int(m.group(3))
146148

147149
self.version = dict(
148150
major=major,

0 commit comments

Comments
 (0)