Browse files

Move signal disconnect into finally block

  • Loading branch information...
1 parent d53e3b1 commit 6045efa029dcae58ec6aab20bdcb0dc325851048 @dcramer dcramer committed Jan 11, 2013
Showing with 6 additions and 4 deletions.
  1. +6 −4 tests/modeltests/delete/tests.py
View
10 tests/modeltests/delete/tests.py
@@ -233,13 +233,15 @@ def test_relational_post_delete_signals_happen_before_parent_object(self):
def log_post_delete(instance, **kwargs):
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)
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")
def test_can_defer_constraint_checks(self):

0 comments on commit 6045efa

Please sign in to comment.