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

change deprecated parameter pw and db #116

Merged
merged 3 commits into from
Mar 16, 2021

Conversation

ziegenberg
Copy link
Contributor

SUMMARY

Parameter db and passed are deprecated in PyMySQL since v1.0.0 and are kept as an alias for database and password. Warnings will be activated around 2022 (for details see PyMySQL/PyMySQL#939).

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

module_utils

ADDITIONAL INFORMATION

@ziegenberg ziegenberg changed the title Fix deprecations change deprecated parameter pw and db Mar 12, 2021
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #116 (095e75c) into main (baea97d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #116   +/-   ##
=======================================
  Coverage   75.75%   75.75%           
=======================================
  Files          12       12           
  Lines        1712     1712           
  Branches      438      438           
=======================================
  Hits         1297     1297           
  Misses        269      269           
  Partials      146      146           
Impacted Files Coverage Δ
plugins/module_utils/mysql.py 83.13% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update baea97d...095e75c. Read the comment docs.

@Andersson007
Copy link
Collaborator

Andersson007 commented Mar 12, 2021

@ziegenberg hi, thanks for the PR!
Please add a changelog fragment with minor_changes: see https://docs.ansible.com/ansible/latest/community/development_process.html#creating-a-changelog-fragment (please follow the format), for example:

minor_changes:
- mysql module utils - change deprecated connection parameters ``passwd`` and ``db`` to ``password`` and ``database`` (https://github.com/ansible-collections/community.mysql/pull/116).

https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html also doesn't recommend to use db and passwd

@bmalynovytch @Jorge-Rodriguez what do you think? As far as i know we test against both pymysql and mysqldb and the tests seem to be green.
If you're ok, feel free to to push the big green button

@ziegenberg
Copy link
Contributor Author

@Andersson007 changelog fragment added.

@Andersson007
Copy link
Collaborator

@ziegenberg thanks! BTW don't worry about codecov

@Andersson007
Copy link
Collaborator

Let's wait for the folks opinion

@Jorge-Rodriguez
Copy link
Contributor

@ziegenberg I'm worried about the backwards compatibility of this change. Do you have the version numbers when these options were deprecated?

@ziegenberg
Copy link
Contributor Author

It was introduced into PyMySQL with this PR on Jun 6, 2014: PyMySQL/PyMySQL#247
If I saw this correctly, it's available at least since version 0.6.3.

@Jorge-Rodriguez
Copy link
Contributor

Jorge-Rodriguez commented Mar 15, 2021

@ziegenberg I'm afraid this change breaks the compatibility with MySQLdb connector that still uses the parameter names deprecated in pymysql, as seen here

But then, the tests pass, so it must be an issue with MySQLdb's documentation, and since we're testing all the connector versions that we support, I suppose it's all good.

@Jorge-Rodriguez Jorge-Rodriguez merged commit 2254b29 into ansible-collections:main Mar 16, 2021
@Andersson007
Copy link
Collaborator

@ziegenberg thanks for the PR!
@Jorge-Rodriguez thanks for reviewing and merging!

@ziegenberg ziegenberg deleted the fix-deprecations branch March 16, 2021 10:26
@ziegenberg
Copy link
Contributor Author

@Jorge-Rodriguez in MySQLdb they also have password and passwd as an alias, so I guess updating the docu, as you said, seems the right approach.

@ziegenberg
Copy link
Contributor Author

Ah, they already have updated the docs in their main branch. See this commit PyMySQL/mysqlclient@fa25358

@tschoonj
Copy link

I am seeing the following error due to this change:

failed: [vm-ip] (item=rfi-stfc-guacamole-vm.novalocal) => {"ansible_loop_var": "item", "changed": false, "item": "rfi-stfc-guacamole-vm.novalocal", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: 'database' is an invalid keyword argument for this function"}

The remote is using MySQL-python-1.2.5-1.el7.x86_64.

@tschoonj
Copy link

Switching to PyMySQL fixed things for me, but looks like backwards compatibility was broken with MySQLdb.

@ziegenberg
Copy link
Contributor Author

I'm not sure if MySQL-python-1.2.5 is a supported version of this collection? It was released in 2014.

@Jorge-Rodriguez
Copy link
Contributor

As of now, only MySQLdb version 2 is supported.

@tschoonj
Copy link

Ok that's fine, but it might be wise to update the docs accordingly.

@Jorge-Rodriguez
Copy link
Contributor

You're very correct about that. And it's actually planned, along with the list of supported server versions.

@awegrzyn
Copy link

awegrzyn commented Apr 22, 2021

Hi,
I've spent a bit of time today to debug an issue with our deployment as we've been getting Exception message: 'database' is an invalid keyword argument for this function".
Would it be possible to deprecate MySQL-python-1.2.5 more gracefully?
Docs still says: Requires the PyMySQL (Python 2.7 and Python 3.X) or MySQL-python, and on C7 MySQL-python brings 1.2.5...
Thanks.

@Jorge-Rodriguez
Copy link
Contributor

Jorge-Rodriguez commented Apr 22, 2021

and on C7 MySQL-python brings 1.2.5...

Is that CentOS 7?

@Andersson007
Copy link
Collaborator

Andersson007 commented Apr 23, 2021

#151

  1. maybe we could just quickly revert this and release? The change doesn't bring a lot in comparison with the consequences

@Andersson007
Copy link
Collaborator

or 2) quick patch like "if this error occurs, use db" ?

@Jorge-Rodriguez
Copy link
Contributor

Let's revert and consider a more seamless approach to reimplement it

@Jorge-Rodriguez
Copy link
Contributor

@ziegenberg could you check what was the version of MySQLdb that introduced the new database and password keywords?

@ziegenberg
Copy link
Contributor Author

A quick check brought up that it might be v1.3.8 in 2016. I'll check thoroughly when I'm back at my desk. Currently only on a mobile.

@Andersson007
Copy link
Collaborator

Reverted with #153. will try to release today.
I think the best approach is to check driver versions and behave correspondingly.
See the surrounding code in the mysql_connect function - there's an example of the check.

Thanks everyone for collaborating!

@Andersson007
Copy link
Collaborator

Released:) Who wants to handle it gracefully now, welcome:)

@Andersson007
Copy link
Collaborator

Available on galaxy https://galaxy.ansible.com/community/mysql. How to install from galaxy, refer to https://galaxy.ansible.com/community/mysql, or wait for the next Ansible package release.

@Andersson007
Copy link
Collaborator

@ziegenberg hi, would you like to continue working on this?

@ziegenberg
Copy link
Contributor Author

I can give it another try. But first, I want to say sorry for the disruption my contribution has caused.

Before implementing this, I guess we need to sort out the supported versions of the connectors. And fix the CI accordingly. I think this should go into a separate PR beforehand.

@Andersson007
Copy link
Collaborator

I can give it another try. But first, I want to say sorry for the disruption my contribution has caused.

Don't worry about it much, this happens to all of us from time to time (for example, I broke and am breaking stuff a lot but it gives valuable experience). It's normal. Now we know that we should be careful about driver versions even if they seem to be absolutely obsolete.

Before implementing this, I guess we need to sort out the supported versions of the connectors. And fix the CI accordingly. I think this should go into a separate PR beforehand.

Sounds very sensible.
I think the related files are stored in .github/workflows/ and tests/integration/targets/setup_mysql/. If i missed something @Jorge-Rodriguez can correct me.

@ziegenberg feel free to create related issues / PRs and ask if there are any questions on your mind.

Thanks!

@Jorge-Rodriguez
Copy link
Contributor

@ziegenberg I'm working on a PR tackling CI versions, you can keep an eye on #163

@ziegenberg
Copy link
Contributor Author

I've created #176 to track the discussion of changing deprecated parameter pw and db.

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.

5 participants