#30571: Incorrect value of kwargs in pre_init signal
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
singhpratyush |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: signals
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I was working on a follower-following system for users.
Model -
{{{
class Follower(models.Model):
follower = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='following')
following = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='followers')
follow_time = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ('follower', 'following')
}}}
I created this `pre_init` signal (to prevent a user from following self,
but details excluded)-
{{{
@receiver(signals.pre_init, sender=user_models.Follower)
def prevent_user_following_self(sender, *args, **kwargs):
print(kwargs)
}}}
After this, I tried the following in Django shell -
{{{
>>> import django
>>> django.__version__
'2.2.2'
>>> from django.contrib.auth.models import User
>>> from users.models import Follower
>>> a = User.objects.get(pk=1)
>>> Follower(follower=a, following=a)
{'signal': <django.db.models.signals.ModelSignal object at
0x7f431561dc88>, 'args': (), 'kwargs': {'follower': <User: admin>,
'following': <User: admin>}}
}}}
Here, `kwargs` contains the actual `kwargs` under a nested name. While
according to the [https://docs.djangoproject.com/en/2.2/ref/signals/#pre-
init documentation], the `print` here should give
{{{
{'kwargs': {'follower': <User: admin>, 'following': <User: admin>}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30571>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/056.a28003417ed1222c459eed69a90ca5ed%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.