﻿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
16663	Model field choices should accept empty iterator	Daniel Naab	nobody	"The base `Field` class constructor uses the following shorthand to initialize the `choices` for a field (line 96 of `django/db/model/fields/__init__.py`):

{{{
self._choices = choices or []
}}}
In Python, an empty iterator evaluates to False, so if we did:

{{{
class MyModel(models.Model):
    my_field = models.IntegerField(choices=my_list_like_object)
}}}

`_choices` will default to an empty list if the `my_list_like_object` is permanently or temporarilly empty at time of class definition.  However, the documentation clearly states the intent of allowing [https://docs.djangoproject.com/en/dev/ref/models/fields/#choices any iterable] as a `choices` kwarg:

    Finally, note that choices can be any iterable object -- not necessarily a list or tuple. This lets you construct choices dynamically. But if you find yourself hacking choices to be dynamic, you're probably better off using a proper database table with a ForeignKey. choices is meant for static data that doesn't change much, if ever.

So I propose making a small change to the above line:

{{{
if choices == None:
    self._choices = []
else:
    self._choices = choices
}}}"	Bug	closed	Database layer (models, ORM)	1.3	Normal	needsinfo		Daniel Naab	Design decision needed	1	0	0	0	0	0
