diff options
| author | Tim Graham <timograham@gmail.com> | 2017-08-31 09:34:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-31 09:34:44 -0400 |
| commit | e5bd585c6eb1e13e2f8aac030b33c077b0b70c05 (patch) | |
| tree | c4ae599950d749a1b67f1b9273bd7458f8fc3e0e /tests/model_forms/tests.py | |
| parent | ec6481246a76f6a3339c987f14c3878f55cd7300 (diff) | |
Fixed #28543 -- Prevented ManyToManyField.value_from_object() from being lazy.
Previously, it was a QuerySet which could reevaluate to a new value if the
model's data changes. This is inconsistent with other Field.value_from_object()
methods.
This allows reverting the fix in the admin for refs #27998.
Diffstat (limited to 'tests/model_forms/tests.py')
| -rw-r--r-- | tests/model_forms/tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 0cfc18659f..7af2aff825 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -3113,3 +3113,18 @@ class StrictAssignmentTests(TestCase): '__all__': ['Cannot set attribute'], 'title': ['This field cannot be blank.'] }) + + +class ModelToDictTests(TestCase): + def test_many_to_many(self): + """Data for a ManyToManyField is a list rather than a lazy QuerySet.""" + blue = Colour.objects.create(name='blue') + red = Colour.objects.create(name='red') + item = ColourfulItem.objects.create() + item.colours.set([blue]) + data = model_to_dict(item)['colours'] + self.assertEqual(data, [blue]) + item.colours.set([red]) + # If data were a QuerySet, it would be reevaluated here and give "red" + # instead of the original value. + self.assertEqual(data, [blue]) |
