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

Intermittent encoding issue in Environment.compile_templates on windows #889

Closed
iljau opened this issue Aug 23, 2018 · 0 comments · Fixed by #1096
Closed

Intermittent encoding issue in Environment.compile_templates on windows #889

iljau opened this issue Aug 23, 2018 · 0 comments · Fixed by #1096
Labels
bug
Milestone

Comments

@iljau
Copy link

@iljau iljau commented Aug 23, 2018

I used Environment.compile_templates on windows compile templates and managed to get UnicodeDecodeError on Python 3. Issue is that when writing templates:

f = open(os.path.join(target, filename), mode)
no explicit encoding is specified for open. In my case it meant, that my utf8 encoded templates got compiled correctly, but then written as cp1252 and failed to load, when executing.

  • When explicitly specifying encoding to 'utf8' in referenced open call compiled templates were functional.
  • Enabling Python 3.7 UTF-8 mode using PYTHONUTF8 also got rid of the issue (which forces utf8 encoding for open calls).

When I tried to provide minimal example, issue didn't trigger (files got written as 'utf8'). Copying all templates from flask project didn't also trigger issue. Then within my flask project issue is triggered, but I didn't notice any changes to encoding there.

In any case used encoding doesn't seem to be deterministic.
Perhaps somebody will experience same issue and will be able to provide minimal example.

Expected Behavior

Compiled templates are written to disk using correct encoding (utf8 in my case).

Actual Behavior

Encoding of compiled templates depends on what open call selects by default.

Your Environment

  • Python version: 3.6.6 / 3.7.0
  • Jinja version: 2.10
@davidism davidism added this to the 2.11.0 milestone Oct 28, 2019
@davidism davidism added the bug label Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.