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 nonetype by adding ensure_required_libs to get_conn_params in postgres.py #253

Merged
merged 13 commits into from
May 5, 2022

Conversation

jchancojr
Copy link
Collaborator

SUMMARY

Fix nonetype by adding ensure_required_libs to get_conn_params in postgres.py

Fixes #252

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

All

@jchancojr jchancojr self-assigned this May 2, 2022
Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jchancojr thanks for fixing this!

changelogs/fragments/252-fix-none-attribute-error.yml Outdated Show resolved Hide resolved
plugins/module_utils/postgres.py Outdated Show resolved Hide resolved
@jchancojr jchancojr requested a review from Andersson007 May 3, 2022 23:54
@jchancojr
Copy link
Collaborator Author

Hi, @Andersson007.

Went with your suggestion and added comments above the ensure_required_libs(module) before connect to DB. Let me know if there are any issues :)

Thanks!

@hunleyd
Copy link
Collaborator

hunleyd commented May 4, 2022

hey @Andersson007 does this pr show conflicts for you? it does for me, but not @jchancojr

also, Jim can't see the actual error log output of the tests, so he can't debug any failures :(

@Andersson007
Copy link
Collaborator

hey @Andersson007 does this pr show conflicts for you? it does for me, but not @jchancojr

@hunleyd i see no conflicts

also, Jim can't see the actual error log output of the tests, so he can't debug any failures :(

Do you mean he can't click the checks to see details?

@Andersson007
Copy link
Collaborator

Andersson007 commented May 4, 2022

@jchancojr thanks!
Also feel free to remove ensure_required_libs from connect_to_db not to invoke it twice. After that we can merge the PR

@Andersson007
Copy link
Collaborator

tests/unit/plugins/module_utils/test_postgres.py::TestConnectToDb

please take a look at this unit test. I think it should be adjusted a little bit (i.e. remove everything related to connect_to_db)
you can run them locally before pushing with ansible-test units /path/to/file --docker

@jchancojr
Copy link
Collaborator Author

please take a look at this unit test. I think it should be adjusted a little bit (i.e. remove everything related to connect_to_db)

New to ansible-test and wasn't able to point it directly at the test_postgres.py file for some reason, but I was able to run ansible-test utils --docker -v on the whole of it, and everything passed.

Example:

[gw6] [ 23%] PASSED tests/unit/plugins/module_utils/test_postgres.py::TestGetConnParams::test_get_conn_params_warn_db_def_false

In the test_postgres.py file I removed the entire call to connect_to_db.

Could use some guidance here probably as I'm not convinced I've done this correctly.

@Andersson007
Copy link
Collaborator

Andersson007 commented May 5, 2022

ah, sorry, i wanted to say remove stuff related to ensure_required_libs from TestConnectToDB:( my bad. I'll raise a PR. It was a tough day yesterday:)

@Andersson007 Andersson007 mentioned this pull request May 5, 2022
@Andersson007 Andersson007 reopened this May 5, 2022
@Andersson007
Copy link
Collaborator

#258

Copy link
Collaborator

@Andersson007 Andersson007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @jchancojr thanks for fixing this!

@Andersson007 Andersson007 merged commit a7f68b8 into ansible-collections:main May 5, 2022
@Andersson007
Copy link
Collaborator

Andersson007 commented May 5, 2022

Guidance from me:

  • when refactoring something and that something is covered by units, they will probably fail
  • so it makes sense to run ansible-test units --docker (it will run all tests) or ansible-test units /path/to/file/ --docker
  • if they fail locally, try to fix them:) in our case we removed the function that checked something and failed if the condition didn't satisfy (in this case, version of psycopg2)
  • the failing check mocked and passed psycopg2 of older version than required, so the check expected the function to fail
  • as we don't have ensure_required_lib in there, the check's expectation is not valid anymore, so it failed
  • so we removed that check (btw ensure_required_libs is also covered separately in that test file)
  • it also makes sense to run ansible-test sanity /path/to/changed/or/added/file --docker locally before pushing

If any questions, just ask

@Andersson007
Copy link
Collaborator

Andersson007 commented May 5, 2022

pytest + unit testing principles are good things to learn. The collection requirements (to be in the package) say that a collection must be covered by units or integration tests.
Some time ago i started to cover things (new stuff and when refactoring) with both and i've concluded that it's really worth doing because:

  • it helped me catch a lot of hidden bugs that i didn't catch with integration tests.
  • it helps make your design better (forces you to write really simple functions that are easy to test).
  • though it's a recommendation (to cover code with both types), not a requirement.
  • unfortunately most of the stuff here is written not in a good manner because it was a long time ago... but, on the other hand, we have space to improve things:)
  • if you wanna try to write something big from scratch for practice, welcome to https://github.com/ansible-collections/community.cockroachdb :)

jchancojr added a commit to jchancojr/community.postgresql that referenced this pull request May 7, 2022
…ty.postgresql

* 'main' of https://github.com/ansible-collections/community.postgresql:
  Remove changelog fragment for doc change.
  Update changelog to reflect doc changes for postgresql_owner.py
  Change documentation to be more clear that the changes take place for the entire cluster/instance rather than just a single DB.
  Fix `nonetype` by adding `ensure_required_libs` to `get_conn_params` in postgres.py (ansible-collections#253)
  Update unit tests (ansible-collections#258)
  docs: announce the new matrix pg room (ansible-collections#254)
@jchancojr jchancojr deleted the issue_252 branch May 11, 2022 13:21
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.

AttributeError: 'NoneType' object has no attribute '__version__'
3 participants