Skip to content

Commit

Permalink
fix: only parse the digits from the pg version (ansible-collections#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Jul 26, 2022
1 parent 7de6946 commit aba4d4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
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 @@ -959,13 +960,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[1])
minor = int(m[2])
patch = None
if len(tmp) >= 3:
patch = int(tmp[2].rstrip(','))
if m[3] is not None:
patch = int(m[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 @@ -137,13 +139,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[1])
minor = int(m[2])
patch = None
if len(tmp) >= 3:
patch = int(tmp[2].rstrip(','))
if m[3] is not None:
patch = int(m[3])

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

0 comments on commit aba4d4e

Please sign in to comment.