Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signals not working for Follow model, potentially others as well. #89

Open
cdrandin opened this issue May 8, 2019 · 0 comments
Open

Comments

@cdrandin
Copy link

cdrandin commented May 8, 2019

I am using Python 3.7.1, Django 2.0.9
This issue apparently was mentioned, but haven't seen any changes to deal with it.

I am trying to use the following signals follower_created, followee_created, following_created.

I connected it like this

@receiver([follower_created, followee_created, following_created], sender=Follow)
def on_following_created(sender, **kwargs):
    print('on_following_created')
    print(kwargs)

I was able to get it to work by changing how the signals were being triggered in the models.py

follower_created.send(sender=self, follower=follower)
followee_created.send(sender=self, followee=followee)
following_created.send(sender=self, following=relation)

to

follower_created.send(sender=self.model, follower=follower)
followee_created.send(sender=self.model, followee=followee)
following_created.send(sender=self.model, following=relation)

assuming the ideal usage:

@receiver(..., sender=Follow)

is for sender to be the model.

Without making any changes to how the signals are triggered.
Connecting would just be

@receiver(..., sender=Follow.objects) # looks weird, but works (not sure intentional usage)

I have not checked the other signals, but I believe any signal being triggered as .send(sender=self) should be changed to .send(sender=self.model).

Edit:

I also tried with follower_removed, followee_removed, following_removed and it does not work with the following connection

@receiver([follower_removed, followee_removed, following_removed], sender=Follow)
def deleteFollowNotification(sender, **kwargs):
    print('deleteFollowNotification')
    print(kwargs)

I had to change

follower_removed.send(sender=rel, follower=rel.follower)
followee_removed.send(sender=rel, followee=rel.followee)
following_removed.send(sender=rel, following=rel)

to

follower_removed.send(sender=rel._meta.model, follower=rel.follower)
followee_removed.send(sender=rel._meta.model, followee=rel.followee)
following_removed.send(sender=rel._meta.model, following=rel)
@receiver([follower_removed, followee_removed, following_removed], sender=Follow.objects) # using Follow.objects

doesn't work either.

in models.py

rel = Follow.objects.get(follower=follower, followee=followee)

is an instance and I have no way of triggering follower_removed, followee_removed, following_removed.

Either sender in .send(sender=MyModel) needs to always be the model class or I am using these signals incorrectly.

I have checked Django release notes and haven't found anything that would change how signals work.

@cdrandin cdrandin changed the title Signals not working for Follow model Signals not working for Follow model, potentially others as well. May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant