Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#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:2 by Tim Graham, 10 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: newclosed

In f7c287fca9c9e6370cc88d1457d3ed9466703687:

Fixed #24073 -- Deactivated translations when leave_locale_alone is False

Thanks Tim Graham and Markus Holtermann for the reviews.

comment:4 by Markus Holtermann, 10 years ago

Has patch: unset
Resolution: fixed
Status: closednew

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

Version 0, edited 10 years ago by Markus Holtermann (next)

comment:5 by Claude Paroz, 10 years ago

Status: newassigned
Triage Stage: Ready for checkinAccepted

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 Markus Holtermann, 10 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:8 by Claude Paroz <claude@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 543df07720181fe23737ba14f1a261ff6f37f49c:

Fixed #24073 -- Returned None for get_language when translations are deactivated

This fixes a regression caused by f7c287fca9. Thanks Markus Holtermann
for identifying the regression.

comment:9 by Tim Graham <timograham@…>, 7 years ago

In b9cec9fa:

Fixed #29017 -- Updated BaseCommand.leave_locale_alone doc per refs #24073.

comment:10 by Tim Graham <timograham@…>, 7 years ago

In 3f951b1:

[2.0.x] Fixed #29017 -- Updated BaseCommand.leave_locale_alone doc per refs #24073.

Backport of b9cec9fa1fc50207ab68a59853c851a945c5db5e from master

comment:11 by Tim Graham <timograham@…>, 7 years ago

In ced0b1e:

[1.11.x] Fixed #29017 -- Updated BaseCommand.leave_locale_alone doc per refs #24073.

Backport of b9cec9fa1fc50207ab68a59853c851a945c5db5e from master

Note: See TracTickets for help on using tickets.
Back to Top