Opened 17 years ago
Last modified 15 years ago
#6783 closed
DecimalField tests with locale — at Version 6
Reported by: | Owned by: | Philippe Raoult | |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Keywords: | i18n-fixed | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I ran into an python locale issue with the DecimalField. During INSERTs and UPDATEs invalid sql-statements are generated since a comma-seperator ',' is used for formating DecimalField instead of the expected dot-seperator '.'
decimal-python.py (for simple testing):
from django.db.models.fields import DecimalField from locale import setlocale, LC_NUMERIC d = DecimalField(max_digits=6, decimal_places=3) setlocale(LC_NUMERIC,'de_DE') print d.format_number(3.456) setlocale(LC_NUMERIC,'en_US') print d.format_number(3.456)
linux-f426d:/home/admin/django/projects # export DJANGO_SETTINGS_MODULE=ais.settings linux-f426d:/home/admin/django/projects # python decimal-python.py 3,456 3.456
Environment:
- Django-SVN
- SuSE Linux Enterprise Server 10
- Python 2.4.2
On my private notebook this is no issue both outputs will be
3.456 3.456
Private Environment:
- Django-SVN
- OpenSuSe 10.3
- Python 2.5.1
Change History (11)
by , 17 years ago
Attachment: | django-DecimalField-prep_locale.patch added |
---|
by , 17 years ago
Attachment: | django-DecimalField-prep_locale.2.patch added |
---|
short work-around for DecimalField format problems in db_prep methods
comment:1 by , 17 years ago
my test machine doesn't have the appropriate locales but I'll run the tests tomorrow.
comment:2 by , 17 years ago
Summary: | DecimalField python locale issue → DecimalField tests with locale |
---|---|
Triage Stage: | Unreviewed → Ready for checkin |
The tests all pass with sqlite and mysql. I tried with both python 2.4.4 and 2.5.1. I'm marking ready for checking so we can commit the regression tests and hopefully get those run with other backends/versions.
Please note that the tests need the 'fr_FR' locale to run. If it's not available the test will be omitted (no failure though). If anyone has a more elegant solution I'd be happy to update the patch :)
comment:3 by , 17 years ago
Owner: | changed from | to
---|
comment:4 by , 17 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Two problems here:
- On a triage level, the test changes should have been part of the main patch. It took a while to realise that this "ready for checkin" thing was actually the second and the fourth patch.
- More importantly, the solution isn't correct.
setlocale()
cannot be used in multi-threaded programs, since it changes the global locale, so it will affect the operation of other threads.
by , 17 years ago
Attachment: | simple_patch.diff added |
---|
comment:5 by , 17 years ago
I'm sorry to hijack this ticket.
I've uploaded a simple_patch.diff that should is a quick and dirty way of sorting this out.
comment:6 by , 16 years ago
Description: | modified (diff) |
---|
short work-around for DecimalField format problems in db_prep methods