#24073 closed Cleanup/optimization (fixed)
Deactivate translations instead of forcing 'en-us' in management commands
| Reported by: | Claude Paroz | Owned by: | Claude Paroz |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
This has been mentioned in #16284, which aims to depart from defaulting to 'en' for JS i18n.
This ticket is concentrating on a similar move for management commands.
Change History (11)
comment:1 by , 11 years ago
| Has patch: | set |
|---|
comment:2 by , 11 years ago
| Triage Stage: | Unreviewed → Ready for checkin |
|---|
comment:3 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:4 by , 11 years ago
| Has patch: | unset |
|---|---|
| Resolution: | fixed |
| Status: | closed → new |
This causes a regression with lazy strings marked for lazy translation.
If you check out https://github.com/MarkusH/django-ticket-triage/commit/54fddd35795f71fea34cf4a166a271f9277e3d19 and run migrate twice, the second time Django will complain that there are changes not reflected by the migrations.
Some of those changes are AlterField operations:
ipdb> changes['conference'][0].operations [<AlterField field=<django.db.models.fields.CharField: name>, preserve_default=True, model_name='audiencelevel', name='name'>, <AlterField field=<django.db.models.fields.CharField: name>, preserve_default=True, model_name='location', name='name'>, <AlterField field=<django.db.models.fields.CharField: name>, preserve_default=True, model_name='section', name='name'>, <AlterField field=<django.db.models.fields.CharField: name>, preserve_default=True, model_name='sessionkind', name='name'>, <AlterField field=<django.db.models.fields.CharField: name>, preserve_default=True, model_name='track', name='name'>]
Inspecting generate_altered_fields() in the migration autodetector yield
> /home/markus/Coding/django/django/db/migrations/autodetector.py(853)generate_altered_fields() 852 import ipdb; ipdb.set_trace() # TODO: debugger --> 853 if (not isinstance(old_field, models.ManyToManyField) and 854 not isinstance(new_field, models.ManyToManyField)): ipdb> old_field_dec ('django.db.models.PositiveSmallIntegerField', [], {'verbose_name': 'action flag'}) ipdb> new_field_dec ('django.db.models.PositiveSmallIntegerField', [], {'verbose_name': <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7f044e1e58d0>})
git bisect pin-points the change to f7c287fca9c9e6370cc88d1457d3ed9466703687
comment:5 by , 11 years ago
| Status: | new → assigned |
|---|---|
| Triage Stage: | Ready for checkin → Accepted |
At least I've understood what's happening. As migrate is calling another management command (loaddata), that last command is restoring the default language code at exit, hence canceling the deactivate_all call from the base command. And then of course, the autodetector is fooled by the translated verbose_name.
Semantically, I think that the root cause is get_language returning settings.LANGUAGE_CODE when translations are deactivated. I'll see if we can safely fix that.
comment:7 by , 11 years ago
| Has patch: | set |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
comment:8 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
https://github.com/django/django/pull/3838