It is demonstrated by the attached small test project.
The most relevant code fragment is:
```
holder = Holder.objects.get(pk=1)
self.assertEqual(holder.items.all().count(), 2, 'Correct objects
count')
```
Django 2.1.7
--
Ticket URL: <https://code.djangoproject.com/ticket/30270>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "bug.tar.gz" added.
Small project to test for the bug
* status: new => closed
* resolution: => invalid
Comment:
I don't see an issue. `Item.objects.create(holder=holder)` populates the
foreign key relation, not the many-to-many relation which is what
`holder.items.count()` is querying. You could make the test case pass
like this (adding `holder.items.set([i1, i2])`):
{{{ #!python
class BugTestCase(TestCase):
def setUp(self):
holder = Holder.objects.create()
i1 = Item.objects.create(holder=holder)
i2 = Item.objects.create(holder=holder)
holder.items.set([i1, i2])
def test_bug(self):
"""Test bug"""
holder = Holder.objects.get(pk=1)
self.assertEqual(holder.items.all().count(), 2, 'Correct objects
count')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30270#comment:1>