Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cast connparams to allow idempotence (#280) #285

Merged
merged 8 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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