Skip to content

Commit f32de83

Browse files
authored
postgresql_alter_system: fix values returned in scientific notation (#854)
1 parent cf1210c commit f32de83

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- postgresql_alter_system - fix failure when max_val contains a huge number written in scientific notation (https://github.com/ansible-collections/community.postgresql/issues/853).

plugins/modules/postgresql_alter_system.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,16 @@ def convert_ret_vals(attrs):
572572
if str_contains_float(attrs[elem]):
573573
attrs[elem] = float(attrs[elem])
574574
else:
575-
attrs[elem] = int(attrs[elem])
575+
try:
576+
attrs[elem] = int(attrs[elem])
577+
except ValueError:
578+
# Leave the attrs[elem] as-is, i.e. a string
579+
# This can happen when max_value of type real
580+
# is huge and written in scientific notation
581+
# e.g., 1.79769e+308 (as of 2025-05-14, this is the only one)
582+
# and it doesn't make sense to convert it as it'll be really huge
583+
# https://github.com/ansible-collections/community.postgresql/issues/853
584+
pass
576585

577586
return attrs
578587

tests/integration/targets/postgresql_alter_system/tasks/test_reals.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,17 @@
108108
- result["diff"]["before"]["setting"] == 1
109109
- result["diff"]["after"]["pending_restart"] == False
110110
- result["diff"]["after"]["setting"] == 1
111+
112+
# http://github.com/ansible-collections/community.postgresql/issues/853
113+
# it should just pass w/o any error
114+
- name: Set value of type real with a max val in scientific notation
115+
<<: *task_parameters
116+
postgresql_alter_system:
117+
<<: *pg_parameters
118+
param: random_page_cost
119+
value: 4
120+
121+
- name: Check max_val
122+
assert:
123+
that:
124+
- result["attrs"]["max_val"] == "1.79769e+308"

0 commit comments

Comments
 (0)