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 can not connect to OneToOneField. #572

Closed
954-Ivory opened this issue Aug 21, 2022 · 2 comments
Closed

Signals can not connect to OneToOneField. #572

954-Ivory opened this issue Aug 21, 2022 · 2 comments

Comments

@954-Ivory
Copy link
Contributor

954-Ivory commented Aug 21, 2022

Because django let sender = self.__class__:
https://github.com/django/django/blob/e9fd2b572410b1236da0d3d0933014138d89f44e/django/db/models/base.py#L860

If you inheritance from PeriodicTask(same as OneToOneField), and overwrite save() in your field, like this:

class YourPeriodicTask(PeriodicTask):
    # ...
    def save(self, *args, **kwargs):
        # ...
        super().save(*args, **kwargs)

The pre_save.sender will be YourPeriodicTask, not PeriodicTask.
So, the signal will not be receive.

@auvipy
Copy link
Member

auvipy commented Aug 21, 2022

is it bug or what you are suggesting?

@954-Ivory
Copy link
Contributor Author

954-Ivory commented Aug 21, 2022

is it bug or what you are suggesting?

Yeah, I think it's a bug.
When we change the PeriodicTask in other Model, if signal can not be receive, the schedulers will not do anything.
This breaks field and scheduler consistency.

954-Ivory added a commit to 954-Ivory/django-celery-beat that referenced this issue Aug 21, 2022
auvipy added a commit that referenced this issue Oct 13, 2022
* Fixed signals can not connect to OneToOneField (#572)

* Remove unused import.

* Changed `PeriodicTasks.pre_save` and `PeriodicTasks.pre_delete` in `PeriodicTasks.save` and `PeriodicTasks.delete`

* Update django_celery_beat/models.py

* Append the unit-test

* Correction of notes

* Append test-case for: O2O-rel instance be deleted

* Add the docs

* Format code according to `pycodestyle`

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
@auvipy auvipy closed this as completed Oct 13, 2022
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

2 participants