Signal receivers must accept keyword arguments (**kwargs).
Package:
django
59414

Exception Class:
ValueError
Raise code
# If DEBUG is on, check that we got a good receiver
if settings.configured and settings.DEBUG:
assert callable(receiver), "Signal receivers must be callable."
# Check for **kwargs
if not func_accepts_kwargs(receiver):
raise ValueError("Signal receivers must accept keyword arguments (**kwargs).")
if dispatch_uid:
lookup_key = (dispatch_uid, _make_id(sender))
else:
lookup_key = (_make_id(receiver), _make_id(sender))
if weak:
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/django/django/blob/7cca22964c09e8dafc313a400c428242404d527a/django/dispatch/dispatcher.py#L87Ways to fix
Error Code:
from django.dispatch import Signal, receiver
from django.conf import settings
settings.configure()
settings.configured = True
settings.DEBUG = True
# Create a custom signal
custom_signal = Signal()
@receiver(custom_signal )
def pong(kwargs):
pass
custom_signal.connect(pong) # <-ValueError: Signal receivers must accept keyword arguments (**kwargs).
Fix code:
from django.dispatch import Signal, receiver
from django.conf import settings
settings.configure()
settings.configured = True
settings.DEBUG = True
# Create a custom signal
custom_signal = Signal()
@receiver(custom_signal)
def pong(**kwargs): # <- You might have missed in this part, where your receiver expecting a variable number of keyword arguments dictionary
pass
custom_signal.connect(pong)
Explanation:
If you see a connect method of Signal class, you'll get-
# Check for **kwargs
if not func_accepts_kwargs(receiver):
raise ValueError("Signal receivers must accept keyword arguments (**kwargs).")
function func_accepts_kwargs contain this piece of code-
def func_accepts_kwargs(func):
"""Return True if function 'func' accepts keyword arguments **kwargs."""
return any(
p for p in _get_callable_parameters(func)
if p.kind == p.VAR_KEYWORD
)
This func_accepts_kwargs function is returning True, if func accepts keyword arguments **kwargs, if not then an error will raise.
Add a possible fix
Please authorize to post fix