From 3965cf0c5ca7b96288b5c35c66fed0beb2d863c6 Mon Sep 17 00:00:00 2001 From: Andrew Klychkov Date: Wed, 14 May 2025 12:02:42 +0200 Subject: [PATCH] postgresql_alter_system: fix values returned in scientific notation --- changelogs/fragments/0-alter_system.yml | 2 ++ plugins/modules/postgresql_alter_system.py | 11 ++++++++++- .../postgresql_alter_system/tasks/test_reals.yml | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/0-alter_system.yml diff --git a/changelogs/fragments/0-alter_system.yml b/changelogs/fragments/0-alter_system.yml new file mode 100644 index 00000000..e09382c0 --- /dev/null +++ b/changelogs/fragments/0-alter_system.yml @@ -0,0 +1,2 @@ +bugfixes: +- 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). diff --git a/plugins/modules/postgresql_alter_system.py b/plugins/modules/postgresql_alter_system.py index 9d7ce3e5..df7658e9 100644 --- a/plugins/modules/postgresql_alter_system.py +++ b/plugins/modules/postgresql_alter_system.py @@ -572,7 +572,16 @@ def convert_ret_vals(attrs): if str_contains_float(attrs[elem]): attrs[elem] = float(attrs[elem]) else: - attrs[elem] = int(attrs[elem]) + try: + attrs[elem] = int(attrs[elem]) + except ValueError: + # Leave the attrs[elem] as-is, i.e. a string + # This can happen when max_value of type real + # is huge and written in scientific notation + # e.g., 1.79769e+308 (as of 2025-05-14, this is the only one) + # and it doesn't make sense to convert it as it'll be really huge + # https://github.com/ansible-collections/community.postgresql/issues/853 + pass return attrs diff --git a/tests/integration/targets/postgresql_alter_system/tasks/test_reals.yml b/tests/integration/targets/postgresql_alter_system/tasks/test_reals.yml index 3dd78a03..b04fa48b 100644 --- a/tests/integration/targets/postgresql_alter_system/tasks/test_reals.yml +++ b/tests/integration/targets/postgresql_alter_system/tasks/test_reals.yml @@ -108,3 +108,17 @@ - result["diff"]["before"]["setting"] == 1 - result["diff"]["after"]["pending_restart"] == False - result["diff"]["after"]["setting"] == 1 + + # http://github.com/ansible-collections/community.postgresql/issues/853 + # it should just pass w/o any error + - name: Set value of type real with a max val in scientific notation + <<: *task_parameters + postgresql_alter_system: + <<: *pg_parameters + param: random_page_cost + value: 4 + + - name: Check max_val + assert: + that: + - result["attrs"]["max_val"] == "1.79769e+308"