#34633: Add prefetch_related() cache invalidation for create() in reverse 
many-to-
one managers.
-------------------------------------+-------------------------------------
     Reporter:  Rob Percival         |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * stage:  Unreviewed => Accepted


Comment:

 Thanks for the report, it seems that it's only missing for `create()` in
 reverse many-to-one managers. It works for many-to-many managers (we could
 add an extra test method for this) and `GenericRelation` (see #29612). See
 a regression test:
 {{{#!diff
 diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
 index 7a6d112a09..d360cd9164 100644
 --- a/tests/many_to_one/tests.py
 +++ b/tests/many_to_one/tests.py
 @@ -799,6 +799,14 @@ class ManyToOneTests(TestCase):
          # refs #21563
          self.assertFalse(hasattr(Article(), "reporter"))

 +    def test_create_after_prefetch(self):
 +        c = City.objects.create(name="Musical City")
 +        d1 = District.objects.create(name="Ladida", city=c)
 +        city = City.objects.prefetch_related("districts").get(id=c.id)
 +        self.assertSequenceEqual(city.districts.all(), [d1])
 +        d2 = city.districts.create(name="Goa")
 +        self.assertSequenceEqual(city.districts.all(), [d1, d2])
 +
      def test_clear_after_prefetch(self):
          c = City.objects.create(name="Musical City")
          d = District.objects.create(name="Ladida", city=c)

 }}}

 Rob, would you like to prepare a patch?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34633#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701888ed04182-c3fa375c-dcd6-41bc-8d31-8cbc1072fcb5-000000%40eu-central-1.amazonses.com.

Reply via email to