If a custom command has custom class variables that are used in handle(),
previously set values are re-used on the next call to the same command
because a new instance is not initialized.
because of:
{{{
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
command = app_name
else:
command = load_command_class(app_name, command_name)
}}}
I have seen this cause issues when the same command is called several
times in a test.
Proposed solution:
Either warn the user about defining custom class level variables, or don't
re-use the initialized command, instead kill the old object and create a
new one on each use. As an optimizaiton we can require this only on custom
commands, and let the base commands keep using the optimized-path with
cached command instance.
Bug introduced in:
https://github.com/django/django/commit/901c3708fb8a2e51bddd37358f8e536282a8c266
--
Ticket URL: <https://code.djangoproject.com/ticket/34765>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.