Changes between Initial Version and Version 2 of Ticket #26706


Ignore:
Timestamp:
Jun 3, 2016, 5:07:32 PM (8 years ago)
Author:
Sharat M R
Comment:
class Test(TestCase):
    def test(self):
        tag = Tag.objects.create(tag='Tag')
        tag.medias.create(name='A')
        tag.medias.create(name='B')
        tag.medias.create(name='C')
        tag = Tag.objects.prefetch_related('medias').get(id=1)
        tag.medias.clear()
        print(tag.medias.all())

This test print all the three medias for me

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26706 – Description

    initial v2  
    2222
    2323The above code prints all the three [m1, m2, m3]. Fetching the tag again using get and printing givens an empty list "[ ]"
     24
     25Failing Testcase
     26
     27{{{
     28class Test(TestCase):
     29    def test(self):
     30        tag = Tag.objects.create(tag='Tag')
     31        tag.medias.create(name='A')
     32        tag.medias.create(name='B')
     33        tag.medias.create(name='C')
     34        tag = Tag.objects.prefetch_related('medias').get(id=1)
     35        tag.medias.clear()
     36        print(tag.medias.all())
     37}}}
     38
     39I guess its related to prefetch_related function.
Back to Top