Skip to content

MySqlHook add support for init_command #33300

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

Closed
2 tasks done
alexbegg opened this issue Aug 11, 2023 · 1 comment · Fixed by #33359
Closed
2 tasks done

MySqlHook add support for init_command #33300

alexbegg opened this issue Aug 11, 2023 · 1 comment · Fixed by #33359

Comments

@alexbegg
Copy link
Contributor

alexbegg commented Aug 11, 2023

Description

There is currently no way to pass an init_command connection argument for a mysql connection when using either the mysqlclient or mysql-connector-python libraries with the MySql provider's MySqlHook.

Documentation for connection arguments for mysqlclient library, listing init_command:
https://mysqlclient.readthedocs.io/user_guide.html?highlight=init_command#functions-and-attributes

Documentation for connection arguments for mysql-connector-python library, listing init_command:
https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html

There can be many uses for init_command, but also what comes to mind is why do we explicitly provide support to certain connection arguments and not others?

Use case/motivation

For my own use right now I am currently am subclassing the hook and then altering the connection arguments to pass in init_command to set the time_zone session variable to UTC at connection time, like so:

conn_config['init_command'] = r"""SET time_zone = '+00:00';"""

Note: This is just an example, there can be many other uses for init_command besides the example above. Also, I am aware there is a time_zone argument for connections via the mysql-connector-python library, however that argument is not supported by connections made with mysqlclient library. Both libraries do support the init_command argument.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@alexbegg alexbegg added kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet labels Aug 11, 2023
@alexbegg alexbegg changed the title MySqlHook init_command MySqlHook add support for init_command Aug 11, 2023
@RNHTTR RNHTTR added area:providers good first issue provider:mysql and removed needs-triage label for new issues that we didn't triage yet labels Aug 11, 2023
@alexbegg
Copy link
Contributor Author

I am working on a PR for this, I just need to make sure the tests pass and if a test DAG covering my example use case works.

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

Successfully merging a pull request may close this issue.

2 participants