Skip to content

Commit

Permalink
fix: Cast connparams to allow idempotence (#280) (#285)
Browse files Browse the repository at this point in the history
* fix: Keep conninfo properties always as string (#280)

* Revert "fix: Keep conninfo properties always as string (#280)"

This reverts commit d284058.

* fix: Cast connparams on subscription update

* Fix: indent issue by accident

* fix: Fix lint errors

* fix: Check for None variable before cast the dict

* Add fragment

* Update changelogs/fragments/285-postgresql_subscription_fix_idempontece.yml

Co-authored-by: Andrew Klychkov <[email protected]>

Co-authored-by: Andrew Klychkov <[email protected]>
  • Loading branch information
jegj and Andersson007 authored Jun 7, 2022
1 parent 56721a1 commit cf4eee2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_subscription - fix idempotence by casting the ``connparams`` dict variable (https://github.com/ansible-collections/community.postgresql/issues/280).
20 changes: 19 additions & 1 deletion plugins/modules/postgresql_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ def convert_subscr_params(params_dict):
return ', '.join(params_list)


def cast_connparams(connparams_dict):
"""Cast the passed connparams_dict dictionary
Returns:
Dictionary
"""
for (param, val) in iteritems(connparams_dict):
try:
connparams_dict[param] = int(val)
except ValueError:
connparams_dict[param] = val

return connparams_dict


class PgSubscription():
"""Class to work with PostgreSQL subscription.
Expand Down Expand Up @@ -368,7 +383,7 @@ def update(self, connparams, publications, subsparams, check_mode=True):
"""Update the subscription.
Args:
connparams (str): Connection string in libpq style.
connparams (dict): Connection dict in libpq style.
publications (list): Publications on the primary to use.
subsparams (dict): Dictionary of optional parameters.
Expand Down Expand Up @@ -683,6 +698,9 @@ def main():
check_mode=module.check_mode)

else:
if connparams:
connparams = cast_connparams(connparams)

changed = subscription.update(connparams,
publications,
subsparams,
Expand Down

0 comments on commit cf4eee2

Please sign in to comment.