Skip to content

Commit

Permalink
fix: only parse the digits from the pg version (#315) (#316) (#321)
Browse files Browse the repository at this point in the history
(cherry picked from commit e1562dc)

Co-authored-by: Rui Lopes <[email protected]>
  • Loading branch information
patchback[bot] and rgl authored Jul 27, 2022
1 parent d6ffb54 commit 32858c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- postgresql_ping - fix pg version parsing (https://github.com/ansible-collections/community.postgresql/issues/315).
- postgresql_info - fix pg version parsing (https://github.com/ansible-collections/community.postgresql/issues/315).
11 changes: 6 additions & 5 deletions plugins/modules/postgresql_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
sample: false
'''

import re
from fnmatch import fnmatch

try:
Expand Down Expand Up @@ -956,13 +957,13 @@ def get_pg_version(self):
query = "SELECT version()"
raw = self.__exec_sql(query)[0][0]
full = raw.split()[1]
tmp = full.split('.')
m = re.match(r"(\d+)\.(\d+)(?:\.(\d+))?", full)

major = int(tmp[0])
minor = int(tmp[1].rstrip(','))
major = int(m.group(1))
minor = int(m.group(2))
patch = None
if len(tmp) >= 3:
patch = int(tmp[2].rstrip(','))
if m.group(3) is not None:
patch = int(m.group(3))

self.pg_info["version"] = dict(
major=major,
Expand Down
12 changes: 7 additions & 5 deletions plugins/modules/postgresql_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
version_added: 1.7.0
'''

import re

try:
from psycopg2.extras import DictCursor
except ImportError:
Expand Down Expand Up @@ -136,13 +138,13 @@ def get_pg_version(self):
self.is_available = True

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

major = int(tmp[0])
minor = int(tmp[1].rstrip(','))
major = int(m.group(1))
minor = int(m.group(2))
patch = None
if len(tmp) >= 3:
patch = int(tmp[2].rstrip(','))
if m.group(3) is not None:
patch = int(m.group(3))

self.version = dict(
major=major,
Expand Down

0 comments on commit 32858c0

Please sign in to comment.