Opened 7 years ago

Closed 5 years ago

#11118 closed Bug (fixed)

BaseCommand doesn't restore translation

Reported by: rvdrijst Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Normal Keywords: basecommand execute syncdb translation testing
Cc: rvdrijst@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


The implementation of BaseCommand.execute() sets the translation to 'en-us' for the duration of the command execution, but doesn't restore the original translation. This is not a problem when execution stops when the command is done (command line use)

However in tests, the syncdb command is called programmatically, running the tests with the 'en-us' translation activated even when this is not the same as settings.LANGUAGE_CODE.

The attached patch fixes this by restoring the language that was activated when the command started.

Note: this ticket is related to #10078, but whereas that ticket is about documentation, this ticket fixes a bug.

Attachments (2)

basecommand.diff (1.5 KB) - added by rvdrijst 7 years ago.
patch with fix (restore translation)
11118-2.diff (2.1 KB) - added by claudep 5 years ago.
Simplify patch and add test

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by rvdrijst

patch with fix (restore translation)

comment:1 Changed 7 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by julien

  • Needs tests set
  • Severity set to Normal
  • Type set to Bug

Changed 5 years ago by claudep

Simplify patch and add test

comment:3 Changed 5 years ago by claudep

  • Component changed from Core (Other) to Core (Management commands)
  • Easy pickings unset
  • Needs tests unset
  • UI/UX unset

comment:4 Changed 5 years ago by ramiro

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 5 years ago by ramiro

  • Resolution set to fixed
  • Status changed from new to closed

In [17077]:

Fixed #11118 -- Made management command BaseCommand restore locale after execution.

Thanks rvdrijst for the report and initial patch and Claude Paroz for enhancing it.

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