Ticket #14043: ticket-14043.patch

File ticket-14043.patch, 1.8 KB (added by gsakkis, 5 years ago)

Moved tests from select_related_onetoone to one_to_one_regress

  • django/db/models/fields/related.py

    diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
    a b  
    225225            db = router.db_for_read(self.related.model, instance=instance)
    226226            rel_obj = self.related.model._base_manager.using(db).get(**params)
    227227            setattr(instance, self.cache_name, rel_obj)
     228            setattr(rel_obj, self.related.field.name, instance)
    228229            return rel_obj
    229230
    230231    def __set__(self, instance, value):
  • tests/regressiontests/one_to_one_regress/models.py

    diff --git a/tests/regressiontests/one_to_one_regress/models.py b/tests/regressiontests/one_to_one_regress/models.py
    a b  
    2626    place = models.OneToOneField(Place, null=True)
    2727    serves_cocktails = models.BooleanField()
    2828
     29    def unlink_place(self):
     30        self.place = None
     31        self.save()
     32
    2933class Favorites(models.Model):
    3034    name = models.CharField(max_length = 50)
    3135    restaurants = models.ManyToManyField(Restaurant)
  • tests/regressiontests/one_to_one_regress/tests.py

    diff --git a/tests/regressiontests/one_to_one_regress/tests.py b/tests/regressiontests/one_to_one_regress/tests.py
    a b  
    128128                Target.objects.exclude(pointer2=None),
    129129                []
    130130        )
     131
     132    def test_not_delete_parent(self):
     133        """Regression test for #14043
     134
     135        Deleting a parent object should not delete the (ex) child after breaking
     136        their link.
     137        """
     138        bar = UndergroundBar.objects.create(place=self.p1, serves_cocktails=False)
     139        self.p1.undergroundbar.unlink_place()
     140        self.p1.delete()
     141        self.assertEqual(UndergroundBar.objects.count(), 1)
Back to Top