Skip to content

Signals can not connect to OneToOneField. #572

@954-Ivory

Description

@954-Ivory

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions