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

Use an explicit encoding when reading the configuration file #1273

Closed
kkirsche opened this issue Jul 14, 2023 · 3 comments
Closed

Use an explicit encoding when reading the configuration file #1273

kkirsche opened this issue Jul 14, 2023 · 3 comments

Comments

@kkirsche
Copy link
Contributor

Describe the bug

When the python option PYTHONWARNDEFAULTENCODING is set as described on https://docs.python.org/3/library/io.html#opt-in-encodingwarning

/Users/kkirsche/Library/Caches/pypoetry/virtualenvs/application-7pVymVLv-py3.11/lib/python3.11/site-packages/alembic/config.py:204: EncodingWarning: 'encoding' argument not specified
  file_config.read([self.config_file_name])

Expected behavior
Alembic will explicitly specify the encoding to use when reading the configuration file. Per https://docs.python.org/3/library/io.html#opt-in-encodingwarning, the recommendation would be to use "utf-8".

To Reproduce
Run an alembic migration with the environment variablePYTHONWARNDEFAULTENCODING set to any value. In my testing, I am using 1 as my value.

Error

/Users/kkirsche/Library/Caches/pypoetry/virtualenvs/application-7pVymVLv-py3.11/lib/python3.11/site-packages/alembic/config.py:204: EncodingWarning: 'encoding' argument not specified
  file_config.read([self.config_file_name])

Versions.

  • OS: macOS 13.4.1 (c) (22F770820d)
  • Python: Python 3.11.4
  • Alembic: 1.11.1
  • SQLAlchemy: 2.0.18[mysql, mypy]
  • Database: mariadb from 11.0.2-MariaDB, client 15.2 for osx10.18 (arm64) using EditLine wrapper
  • DBAPI: mysqlclient 2.2.0

Additional context
The read function passes the encoding to https://docs.python.org/3/library/io.html#io.text_encoding

For me, this returns "locale" which may make sense to use if you are not comfortable with "utf-8". "locale" which, as I understand it, uses https://docs.python.org/3/library/locale.html to detect the encoding settings of the caller's machine.

Thank you for your consideration

Have a nice day!

@kkirsche kkirsche added the requires triage New issue that requires categorization label Jul 14, 2023
@zzzeek zzzeek added bug Something isn't working command interface PRs (with tests!) welcome and removed requires triage New issue that requires categorization labels Jul 14, 2023
@zzzeek
Copy link
Member

zzzeek commented Jul 14, 2023

that's fine, can you please send a pull request? thanks

kkirsche added a commit to kkirsche/alembic that referenced this issue Jul 14, 2023
Fix sqlalchemy#1273

This merge request explicitly sets the encoding of the configuration file being read to "utf-8" as recommended by https://docs.python.org/3/library/io.html#opt-in-encodingwarning
kkirsche added a commit to kkirsche/alembic that referenced this issue Jul 14, 2023
Fix sqlalchemy#1273

This merge request explicitly sets the encoding of the configuration file being read to "utf-8" as recommended by https://docs.python.org/3/library/io.html#opt-in-encodingwarning
@kkirsche
Copy link
Contributor Author

Course, sent 🙂

Thank you for your time and consideration.

@sqla-tester
Copy link
Collaborator

Kevin Kirsche has proposed a fix for this issue in the main branch:

Specify "locale" encoding when reading configuration file https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4786

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.

3 participants