﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29178	Index.__init__()'s fields parameter shouldn't be mutable	Flavio Curella	Atul mishra	"the {{{__init__}}} method of the {{{Index}}} class has the following signature (https://github.com/django/django/blob/master/django/db/models/indexes.py#L15):

{{{
    def __init__(self, *, fields=[], name=None, db_tablespace=None):
}}}

The {{{fields}}} argument is set to a mutable object, which is usually considered bad practice as it can lead to unexpected results:

* http://effbot.org/zone/default-values.htm
* http://docs.python-guide.org/en/latest/writing/gotchas/

There are some valid uses of mutable defaults, but I can't see any code taking advantage of the mutability by looking at the code of the {{{Index}}} class.

If there's no good reason for the default to be mutable, it should be changed to:
{{{
    def __init__(self, *, fields=None, name=None, db_tablespace=None):
        if fields is None:
            fields = []
        # ...rest of the code
}}}

If there's a good reason, I think we should document it in a comment."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	1	0
