Move signal disconnect into finally block
This commit is contained in:
parent
d53e3b15ee
commit
6045efa029
|
@ -233,13 +233,15 @@ class DeletionTests(TestCase):
|
||||||
def log_post_delete(instance, **kwargs):
|
def log_post_delete(instance, **kwargs):
|
||||||
self.assertTrue(R.objects.filter(pk=instance.r_id))
|
self.assertTrue(R.objects.filter(pk=instance.r_id))
|
||||||
|
|
||||||
models.signals.post_delete.connect(log_post_delete, sender=S)
|
|
||||||
|
|
||||||
r = R.objects.create(pk=1)
|
r = R.objects.create(pk=1)
|
||||||
S.objects.create(pk=1, r=r)
|
S.objects.create(pk=1, r=r)
|
||||||
r.delete()
|
|
||||||
|
|
||||||
models.signals.post_delete.disconnect(log_post_delete)
|
models.signals.post_delete.connect(log_post_delete, sender=S)
|
||||||
|
|
||||||
|
try:
|
||||||
|
r.delete()
|
||||||
|
finally:
|
||||||
|
models.signals.post_delete.disconnect(log_post_delete)
|
||||||
|
|
||||||
@skipUnlessDBFeature("can_defer_constraint_checks")
|
@skipUnlessDBFeature("can_defer_constraint_checks")
|
||||||
def test_can_defer_constraint_checks(self):
|
def test_can_defer_constraint_checks(self):
|
||||||
|
|
Loading…
Reference in New Issue