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

Conversation

jegj
Copy link
Contributor

@jegj jegj commented Jun 3, 2022

SUMMARY

Fixes #280. postgresql_subscription module is not idempotent because the port is cast to int in the following chunk of code( 335):

                try:
                    self.attrs['conninfo'][tmp[0]] = int(tmp[1])
                except ValueError:
                    self.attrs['conninfo'][tmp[0]] = tmp[1]

On line 385 the if condition always return false because variable connparams is a dict of string

            if connparams != self.attrs['conninfo']:
                changed = self.__set_conn_params(convert_conn_params(connparams),
                                                 check_mode=check_mode)
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

postgresql_subscription

ADDITIONAL INFORMATION

@hunleyd
Copy link
Collaborator

hunleyd commented Jun 4, 2022

thank you very much for the PR @jegj . Can you fix the failing tests and include a changelog fragment?

@Andersson007
Copy link
Collaborator

Andersson007 commented Jun 6, 2022

@jegj thanks for the fix!
i'm not sure if the patch is safe
Look (this is from our CI):

01:31    "invocation": {
01:31             "connparams": {
01:31                 "dbname": "acme_db",
01:31                 "host": "127.0.0.1",
01:31                 "password": "alsdjfKJKDf1#",
01:31                 "port": 5433,
01:31                 "user": "logical_replication"
01:31             },

The port can be passed as int. How does you playbook look, do you pass it as "5433" probably?
Then yeah it's a bug (which appear when we pass it as string) but if we merge the PR, it'll break things for users who pass the port as int.
In this case we should fix it by doing the same for connparams as we do for self.attrs['conninfo'] (with that try-except).
I suggest adding a function which will do it for connparams.
What do you think?
p.s. I'm not 100% sure my logic is correct

@jegj
Copy link
Contributor Author

jegj commented Jun 6, 2022

@Andersson007 I pass the port as int. I tried with string, same problem. But you are right, that is a better solution. I will add that block code

@Andersson007
Copy link
Collaborator

@Andersson007 I pass the port as int. I tried with string, same problem. But you are right, that is a better solution. I will add that block code

@jegj strange, i should check it, maybe it's converted to string internally somehow but ansible output shows as it's int..

@jegj
Copy link
Contributor Author

jegj commented Jun 6, 2022

@Andersson007 I have added the function but still getting errors on CI. I will take a deep look and see what's the problem

@Andersson007
Copy link
Collaborator

@jegj just a fyi, you can run the integration tests locally before pushing, see https://docs.ansible.com/ansible/devel/community/create_pr_quick_start.html. It'll save a bit of time as it's faster than waiting for results here

@Andersson007
Copy link
Collaborator

@jegj could you also please add a changelog fragment as @hunleyd mentioned?

@jegj
Copy link
Contributor Author

jegj commented Jun 6, 2022

@Andersson007 thanks for the info. Yes! I will add the changelog fragment shortly. Thanks all for the help, first time collaborating on an ansible collection. I should have read the documentation better

@jegj jegj changed the title fix: Keep conninfo properties always as string (#280) fix: Cast connparams to allow idempotence (#280) Jun 6, 2022
@Andersson007 Andersson007 merged commit cf4eee2 into ansible-collections:main Jun 7, 2022
@patchback
Copy link

patchback bot commented Jun 7, 2022

Backport to stable-1: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-1/cf4eee27bd91c24f675d024d4db6bf032ce245cd/pr-285

Backported as #289

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jun 7, 2022
* 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]>
(cherry picked from commit cf4eee2)
@Andersson007
Copy link
Collaborator

@jegj thanks very much for the contribution! We'll be happy to see more by you and help whenever needed!

Andersson007 pushed a commit that referenced this pull request Jun 7, 2022
* 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]>
(cherry picked from commit cf4eee2)

Co-authored-by: Javier <[email protected]>
@jegj
Copy link
Contributor Author

jegj commented Jun 7, 2022

Happy to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

postgresql_subscription module is not idempotent
3 participants