Opened 11 years ago
Closed 11 years ago
#21762 closed Bug (needsinfo)
django.core.files.Storage#save does not respect settings.FILE_CHARSET
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | File uploads/storage | Version: | 1.6 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Assuming that chunk
is not an instance of bytes
, this line:
will create a text-mode file without setting the encoding to settings.FILE_CHARSET
. As a result, my CI builds were failing with UnicodeEncodeError
s on invocation of manage.py collectstatic
(which invoked django-pipeline, which uses this code).
Change History (3)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Apparently the meaning of os.fdopen
has changed in Python 3, which is what I'm using. The encoding
kwarg is probably not accepted in Python 2, so maybe change it to use plain open
if it needs to open in text mode.
comment:3 by , 11 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
settings.FILE_CHARSET
is documented and used in Django for reading files, not for writing files. If you get a UnicodeEncodeError
, I guess you have an issue with your default encoding. On Python 3 (which is the target here), I think that the default encoding is generally always UTF-8. Can you check that (locale.getpreferredencoding
)?
I suggest changing the code under
if _file is None:
to the following: