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

Default encoding of .env and .flaskenv #3931

Closed
bbc2 opened this issue Mar 10, 2021 · 1 comment · Fixed by #3932
Closed

Default encoding of .env and .flaskenv #3931

bbc2 opened this issue Mar 10, 2021 · 1 comment · Fixed by #3932
Milestone

Comments

@bbc2
Copy link

bbc2 commented Mar 10, 2021

I maintain python-dotenv, which Flask uses for loading .env and .flaskenv files, and we've received reports from users confused about the default encoding used by our library: theskumar/python-dotenv#300, which brings me here because it also involves Flask.

Currently, python-dotenv uses the system's preferred encoding to load and store .env files. Since Flask uses dotenv.load_dotenv without the encoding parameter, it inherits that behavior. This means that the encoding of a user's .env or .flaskenv depends on their platform, if I understand Flask's code correctly.

Hence my suggestion: What about making Flask use UTF-8 encoding with the encoding="utf-8" argument?

I don't know if the current behavior was deliberately implemented, and you might want to keep it anyway, but I suspect that it wasn't.

I'm considering making UTF-8 the default in python-dotenv as well, but I'd like your opinion on this since Flask has so many users and relies on python-dotenv's current behavior with respect to encoding.

Here's what it would likely imply for us, and probably also for Flask if it also chooses to use UTF-8:

  • Pro: It would facilitate sharing .env files between projects since the default encoding would be independent of the platform. Those files aren't really meant to be committed in a repository but it's quite typical for developers to have a sample .env in their repository.
  • Pro: It would make .env files use the same encoding, by default, as those of Python source files.
  • Con: It would be a breaking change, but only for users with a non-UTF-8 system encoding and non-UTF-8 strings in their .env files.
  • Con: It would diverge from Python's handling of the encoding parameter in functions like open.

Does that make sense? I've only started thinking about this and I'm not an expert with regards to Python's handling of encodings so I may well have missed an important point.

@greyli
Copy link
Member

greyli commented Mar 10, 2021

Thank you for reporting this issue back to Flask. I would agree to set the default encoding to UTF-8 in Flask (and python-dotenv), just made a PR for it.

I don't know if the current behavior was deliberately implemented, and you might want to keep it anyway, but I suspect that it wasn't.

python-dotenv doesn't add the encoding argument yet when the flask.cli.load_dotenv function was written...

@davidism davidism added this to the 2.0.0 milestone Mar 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants