#21358 closed Bug (fixed)
runserver command fails to run with a non-english locale
Reported by: | SvartalF | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
runserver management command writes current datetime to stdout while starting. With a non-english locale it fails for python2.7.3:
svartalf@wonderland:~/projects/irk [django-1.6-upgrade]$ .env/bin/python manage.py runserver Validating models... 0 errors found Unhandled exception in thread started by <function wrapper at 0x1ec10c8> Traceback (most recent call last): File "/home/svartalf/projects/irk/.env/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper fn(*args, **kwargs) File "/home/svartalf/projects/irk/.env/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run "quit_command": quit_command, File "/home/svartalf/projects/irk/.env/lib/python2.7/site-packages/django/core/management/base.py", line 65, in write if ending and not msg.endswith(ending): UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
I've found that msg variable contains that text with type <type 'str'>:
Октябрь 31, 2013 - 14:30:02 Django version 1.6c1, using settings 'settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C
And it comes from that line of code:
https://github.com/django/django/blob/2ca00faa913754cd5860f6e1f23c8da2529c691a/django/core/management/commands/runserver.py#L105
I wrapped it with a django.utils.text.smart_text and works. Here is a link to my fork commit: https://github.com/svartalf/django/commit/76c058de1bab989c296403e8199aa5fe7f0f83f9
I can pull request it, or maybe, datetime format can be changed to something locale-independent.
Attachments (1)
Change History (6)
comment:1 by , 11 years ago
Has patch: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Nope, I still get that error:
svartalf@wonderland:~/projects/irk [django-1.6-upgrade]$ .env/bin/python manage.py runserver Validating models... 0 errors found Unhandled exception in thread started by <function wrapper at 0x2cf6140> Traceback (most recent call last): File "/home/svartalf/projects/irk/.env/lib/python2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper fn(*args, **kwargs) File "/home/svartalf/projects/irk/.env/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run "quit_command": quit_command, UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
by , 11 years ago
Attachment: | 21358.diff added |
---|
comment:3 by , 11 years ago
Ah yes, strftime
is always returning a bytestring on Python 2, even when the formatting string is unicode. So my patch above workarounds that.
Of course, your patch is shorter and counts on the fact that on Python 2, if there are any unicode parameters in a text substitution, the resulting string is always unicode. But in any case, your patch should use force_text
, smart_text
is only useful when we may have a lazy string as parameter.
comment:4 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Could you test by simply adding that import at the top of the file: