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

[BUG?] post_publish Signal replacement arguments #414

Closed
Will-Hoey opened this issue Jul 10, 2024 · 4 comments
Closed

[BUG?] post_publish Signal replacement arguments #414

Will-Hoey opened this issue Jul 10, 2024 · 4 comments

Comments

@Will-Hoey
Copy link

Will-Hoey commented Jul 10, 2024

As of CMS v4, the publish signals have been moved into versioning. In one of our projects we use django-elasticsearch-dsl in order to search on Title/PageContent objects. We used the signals to update the index on Page publish/unpublish.

def setup(self):
    super().setup()
    post_unpublish.connect(self.handle_save)
    post_publish.connect(self.handle_save)

Which roughly translates to

def setup(self):
    super().setup()
    post_version_operation.connect(self.handle_save)

However, there is a small difference in the way that the signals are sent
https://github.com/django-cms/django-cms/blob/release/3.11.x/cms/models/pagemodel.py#L1007 vs

The old way seems to adhere more to what libraries like Elasticsearch are expecting by sending instance as the arg rather than the new obj.

Happy to work around this if there are other reasons why this was changed, just curious if this was an intended decision?

Note:
Workaround this by overriding the handle_save method in the SignalProcessor from django-elasticsearch-dsl to account for either the instance or obj arguments.

def handle_save(self, sender, instance=None, **kwargs):
    """Handle save.

    Given an individual model instance, update the object in the index.
    Update the related objects either.
    """
    instance = instance or kwargs.get("obj")
    super().handle_save(sender, instance, **kwargs)
``
@Will-Hoey
Copy link
Author

@fsbraun any thoughts on this?

(Sorry not sure if you're the right person to tag!)

@marksweb
Copy link
Member

@Will-Hoey Fabian certainly is the right person to tag. Our expert in the majority of things these days.

@fsbraun
Copy link
Member

fsbraun commented Jul 23, 2024

@Will-Hoey Sorry, I don't know why the signature changed. (Most of what I know is there's been a change to the signals here: #348).

We need to assume that the current signal signatures are used. If there is a good reason to change it, we would need a deprecation period, during which both signatures work. That would require to send both obj and instance parameters. I am not sure if that will cause any side effects.

@Will-Hoey
Copy link
Author

@fsbraun Not a problem. We can work around this for now as we don't use it all that often. Thanks for the reply.

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

3 participants