Skip to content

Use an explicit encoding when reading the configuration file #1273

Description

@kkirsche

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!

Activity

  1. zzzeek commented on Jul 14, 2023

    @zzzeek
    Member

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

  2. added 2 commits that reference this issue on Jul 14, 2023
    9cd00e0
    0c6975e
  3. kkirsche commented on Jul 14, 2023

    @kkirsche
    ContributorAuthor

    Course, sent 🙂

    Thank you for your time and consideration.

  4. sqla-tester commented on Aug 16, 2023

    @sqla-tester
    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

  5. added a commit that references this issue on Sep 27, 2024
    63be916
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions