﻿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
24483	keepdb migrations break choices as generators	David Szotten	Tim Graham <timograham@…>	"So, not got to the bottom of this yet, but wanted to get a ticket in, in case we want to block the release on this

To reproduce:

{{{
# models.py
from django.db import models


def gen():
    for x in 'abc':
        yield (x, x)

class MyModel(models.Model):
    foo = models.CharField(choices=gen(), max_length=1)


# settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'TEST': {
            # make sure we use a db we can keep between tests
            'NAME': os.path.join(BASE_DIR, 'test_db.sqlite3'),
        },
    }
}

# tests.py

from django.test import TestCase

from .models import MyModel


class Test(TestCase):
    def test_choices(self):
        field = MyModel._meta.get_field('foo')
        expected = [('a', 'a'), ('b', 'b'), ('c', 'c')]
        self.assertEqual(
            list(field.choices),
            expected,
        )


# shell (note; need to run twice; only happens when re-using db)
$ ./manage.py test -v2 -k
$ ./manage.py test -v2 -k

======================================================================
FAIL: test_choices (app.tests.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/Users/david/dev/django_bugs/choices_generator/app/tests.py"", line 12, in test_choices
    expected,
AssertionError: Lists differ: [] != [('a', 'a'), ('b', 'b'), ('c',...

Second list contains 3 additional elements.
First extra element 0:
('a', 'a')

- []
+ [('a', 'a'), ('b', 'b'), ('c', 'c')]
}}}


interestingly, this only breaks when `verbosity` is 2, i think because this is the trigger:
https://github.com/django/django/blob/a52cd407b86a51e1badf6771e590361e24fd7155/django/core/management/commands/migrate.py#L177"	Bug	closed	Migrations	1.8beta2	Normal	fixed	migrations test keepdb		Accepted	1	0	0	0	0	0
