mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #24483 -- Prevented keepdb from breaking with generator choices.
If Field.choices is provided as an iterator, consume it in __init__ instead of using itertools.tee (which ends up holding everything in memory anyway). Fixes a bug where deconstruct() was consuming the iterator but bypassing the call to `tee`.
This commit is contained in:
committed by
Tim Graham
parent
118cae2df8
commit
80e3444eca
@@ -595,6 +595,26 @@ class StateTests(TestCase):
|
||||
self.assertIsNot(old_model.food_mgr.model, new_model.food_mgr.model)
|
||||
self.assertIsNot(old_model.food_qs.model, new_model.food_qs.model)
|
||||
|
||||
def test_choices_iterator(self):
|
||||
"""
|
||||
#24483 - ProjectState.from_apps should not destructively consume
|
||||
Field.choices iterators.
|
||||
"""
|
||||
new_apps = Apps(["migrations"])
|
||||
choices = [('a', 'A'), ('b', 'B')]
|
||||
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
choice = models.CharField(max_length=255, choices=iter(choices))
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
apps = new_apps
|
||||
|
||||
ProjectState.from_apps(new_apps)
|
||||
choices_field = Author._meta.get_field('choice')
|
||||
self.assertEqual(list(choices_field.choices), choices)
|
||||
|
||||
|
||||
class ModelStateTests(TestCase):
|
||||
def test_custom_model_base(self):
|
||||
|
||||
Reference in New Issue
Block a user