mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #26778 -- Fixed ModelSignal.connect() weak argument.
This commit is contained in:
parent
8ba44ecda0
commit
9bf8d50a67
@ -27,7 +27,10 @@ class ModelSignal(Signal):
|
||||
return partial_method(sender)
|
||||
|
||||
def connect(self, receiver, sender=None, weak=True, dispatch_uid=None, apps=None):
|
||||
self._lazy_method(super(ModelSignal, self).connect, apps, receiver, sender, dispatch_uid=dispatch_uid)
|
||||
self._lazy_method(
|
||||
super(ModelSignal, self).connect, apps, receiver, sender,
|
||||
weak=weak, dispatch_uid=dispatch_uid,
|
||||
)
|
||||
|
||||
def disconnect(self, receiver=None, sender=None, weak=None, dispatch_uid=None, apps=None):
|
||||
if weak is not None:
|
||||
|
@ -4,7 +4,7 @@ from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.db.models import signals
|
||||
from django.dispatch import receiver
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, mock
|
||||
from django.test.utils import isolate_apps
|
||||
from django.utils import six
|
||||
|
||||
@ -258,6 +258,19 @@ class SignalTests(BaseSignalTest):
|
||||
self.assertTrue(b._run)
|
||||
self.assertEqual(signals.post_save.receivers, [])
|
||||
|
||||
@mock.patch('weakref.ref')
|
||||
def test_lazy_model_signal(self, ref):
|
||||
def callback(sender, args, **kwargs):
|
||||
pass
|
||||
signals.pre_init.connect(callback)
|
||||
signals.pre_init.disconnect(callback)
|
||||
self.assertTrue(ref.called)
|
||||
ref.reset_mock()
|
||||
|
||||
signals.pre_init.connect(callback, weak=False)
|
||||
signals.pre_init.disconnect(callback)
|
||||
ref.assert_not_called()
|
||||
|
||||
|
||||
class LazyModelRefTest(BaseSignalTest):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user