diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index bea88ba..01b8a55 100644
a
|
b
|
class ReverseManyRelatedObjectsDescriptor(object):
|
904 | 904 | raise AttributeError("Cannot set values on a ManyToManyField which specifies an intermediary model. Use %s.%s's Manager instead." % (opts.app_label, opts.object_name)) |
905 | 905 | |
906 | 906 | manager = self.__get__(instance) |
| 907 | # clear() can change expected output of 'value' queryset, we force evaluation |
| 908 | # of queryset before clear; ticket #19816 |
| 909 | value = tuple(value) |
907 | 910 | manager.clear() |
908 | 911 | manager.add(*value) |
909 | 912 | |
diff --git a/tests/regressiontests/m2m_regress/tests.py b/tests/regressiontests/m2m_regress/tests.py
index 3dc1d24..90aab5e 100644
a
|
b
|
from django.test import TestCase
|
5 | 5 | from django.utils import six |
6 | 6 | |
7 | 7 | from .models import (SelfRefer, Tag, TagCollection, Entry, SelfReferChild, |
8 | | SelfReferChildSibling, Worksheet, RegressionModelSplit) |
| 8 | SelfReferChildSibling, Worksheet, RegressionModelSplit, Line) |
9 | 9 | |
10 | 10 | |
11 | 11 | class M2MRegressionTests(TestCase): |
… |
… |
class M2MRegressionTests(TestCase):
|
96 | 96 | # causes a TypeError in add_lazy_relation |
97 | 97 | m1 = RegressionModelSplit(name='1') |
98 | 98 | m1.save() |
| 99 | |
| 100 | def test_m2m_filter(self): |
| 101 | worksheet = Worksheet.objects.create(id=1) |
| 102 | line_hi = Line.objects.create(name="hi") |
| 103 | line_bye = Line.objects.create(name="bye") |
| 104 | |
| 105 | worksheet.lines = [line_hi, line_bye] |
| 106 | hi = worksheet.lines.filter(name="hi") |
| 107 | |
| 108 | worksheet.lines = hi |
| 109 | self.assertEquals(1, worksheet.lines.count()) |
| 110 | self.assertEquals(1, hi.count()) |
| 111 | |