#24483: keepdb migrations break choices as generators
-------------------------------+------------------------------------
     Reporter:  davidszotten   |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Migrations     |    Version:  1.8beta2
     Severity:  Normal         |   Keywords:  migrations test keepdb
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+------------------------------------
 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

--
Ticket URL: <https://code.djangoproject.com/ticket/24483>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.bdae5000eabd8916ce58312a5a5f70fc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to