Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed some Signal.disconnect calls from 058e434.

This would go unnoticed by the test suite because receivers are removed
automatically when they are garbage collected.

Changed all Signal.connect calls to hold strong references to ensure we
clean up after ourselves.
  • Loading branch information...
commit 3f19b63f8b7d70fde838d6949eab28e2c8d8ca99 1 parent 97ac22e
@loic loic authored charettes committed
Showing with 23 additions and 23 deletions.
  1. +23 −23 tests/signals/tests.py
View
46 tests/signals/tests.py
@@ -43,8 +43,8 @@ def post_save_handler(signal, sender, instance, **kwargs):
(instance, kwargs.get("created"), kwargs.get("raw", False))
)
- signals.pre_save.connect(pre_save_handler)
- signals.post_save.connect(post_save_handler)
+ signals.pre_save.connect(pre_save_handler, weak=False)
+ signals.post_save.connect(post_save_handler, weak=False)
try:
p1 = Person.objects.create(first_name="John", last_name="Smith")
@@ -85,8 +85,8 @@ def post_save_handler(signal, sender, instance, **kwargs):
(p2, True, False),
])
finally:
- signals.post_delete.disconnect(pre_save_handler)
- signals.pre_delete.disconnect(post_save_handler)
+ signals.pre_save.disconnect(pre_save_handler)
+ signals.post_save.disconnect(post_save_handler)
def test_delete_signals(self):
data = []
@@ -107,8 +107,8 @@ def __call__(self, signal, sender, instance, **kwargs):
)
post_delete_handler = PostDeleteHandler(data)
- signals.pre_delete.connect(pre_delete_handler)
- signals.post_delete.connect(post_delete_handler)
+ signals.pre_delete.connect(pre_delete_handler, weak=False)
+ signals.post_delete.connect(post_delete_handler, weak=False)
try:
p1 = Person.objects.create(first_name="John", last_name="Smith")
p1.delete()
@@ -137,17 +137,17 @@ def __call__(self, signal, sender, instance, **kwargs):
six.text_type
)
finally:
- signals.post_delete.disconnect(pre_delete_handler)
- signals.pre_delete.disconnect(post_delete_handler)
+ signals.pre_delete.disconnect(pre_delete_handler)
+ signals.post_delete.disconnect(post_delete_handler)
def test_decorators(self):
data = []
- @receiver(signals.pre_save)
+ @receiver(signals.pre_save, weak=False)
def decorated_handler(signal, sender, instance, **kwargs):
data.append(instance)
- @receiver(signals.pre_save, sender=Car)
+ @receiver(signals.pre_save, sender=Car, weak=False)
def decorated_handler_with_sender_arg(signal, sender, instance, **kwargs):
data.append(instance)
@@ -155,8 +155,8 @@ def decorated_handler_with_sender_arg(signal, sender, instance, **kwargs):
c1 = Car.objects.create(make="Volkswagon", model="Passat")
self.assertEqual(data, [c1, c1])
finally:
- signals.post_delete.disconnect(decorated_handler)
- signals.pre_delete.disconnect(decorated_handler_with_sender_arg, sender=Car)
+ signals.pre_save.disconnect(decorated_handler)
+ signals.pre_save.disconnect(decorated_handler_with_sender_arg, sender=Car)
def test_save_and_delete_signals_with_m2m(self):
data = []
@@ -177,17 +177,17 @@ def post_save_handler(signal, sender, instance, **kwargs):
data.append('Is raw')
def pre_delete_handler(signal, sender, instance, **kwargs):
- data.append('pre_save signal, %s' % instance)
+ data.append('pre_delete signal, %s' % instance)
data.append('instance.id is not None: %s' % (instance.id is not None))
def post_delete_handler(signal, sender, instance, **kwargs):
data.append('post_delete signal, %s' % instance)
data.append('instance.id is not None: %s' % (instance.id is not None))
- signals.pre_save.connect(pre_save_handler)
- signals.post_save.connect(post_save_handler)
- signals.pre_delete.connect(pre_delete_handler)
- signals.post_delete.connect(post_delete_handler)
+ signals.pre_save.connect(pre_save_handler, weak=False)
+ signals.post_save.connect(post_save_handler, weak=False)
+ signals.pre_delete.connect(pre_delete_handler, weak=False)
+ signals.post_delete.connect(post_delete_handler, weak=False)
try:
a1 = Author.objects.create(name='Neal Stephenson')
self.assertEqual(data, [
@@ -211,10 +211,10 @@ def post_delete_handler(signal, sender, instance, **kwargs):
b1.authors = []
self.assertEqual(data, [])
finally:
- signals.post_delete.disconnect(pre_save_handler)
- signals.pre_delete.disconnect(post_save_handler)
- signals.post_save.disconnect(pre_delete_handler)
- signals.pre_save.disconnect(post_delete_handler)
+ signals.pre_save.disconnect(pre_save_handler)
+ signals.post_save.disconnect(post_save_handler)
+ signals.pre_delete.disconnect(pre_delete_handler)
+ signals.post_delete.disconnect(post_delete_handler)
def test_disconnect_in_dispatch(self):
"""
@@ -232,8 +232,8 @@ def __call__(self, signal, sender, **kwargs):
signal.disconnect(receiver=self, sender=sender)
a, b = Handler(1), Handler(2)
- signals.post_save.connect(sender=Person, receiver=a)
- signals.post_save.connect(sender=Person, receiver=b)
+ signals.post_save.connect(a, sender=Person, weak=False)
+ signals.post_save.connect(b, sender=Person, weak=False)
Person.objects.create(first_name='John', last_name='Smith')
self.assertTrue(a._run)
Please sign in to comment.
Something went wrong with that request. Please try again.