wagtail / wagtail

A Django content management system focused on flexibility and user experience
https://wagtail.org
BSD 3-Clause "New" or "Revised" License
17.86k stars 3.77k forks source link

Image focal points aren't updated when saved #11026

Open krieghan opened 11 months ago

krieghan commented 11 months ago

Issue Summary

When updating an image focal point in the edit interface, edits aren't reflected on the page. This seems to be due to caching. The Rendition object is cached, along with the focal point cached_property. This cache doesn't seem to be invalidated on save, nor is the object in the cache updated. This means that the value of the focal point in the database is correct, but the focal point from the cache is not. Consequently, as stated, the page will continue to show the old focal point until the cache is manually invalidated

Steps to Reproduce

  1. Create a page with an image with a given focal point
  2. Update the image to have a new focal point
  3. Note on the preview page that the image's focal point still shows the old value

Technical details

krieghan commented 11 months ago

Adding this to wagtail.images.signal_handlers does seem to be sufficient to solve the problem:

def purge_image_renditions_cache(image, **kwargs):
    for rendition in image.renditions.all():
        renditions.purge_from_cache()

(assuming this line has been added to register_signal_handlers):

    post_save.connect(purge_image_renditions_cache, sender=Image)

Just adding this for context for the problem I'm seeing, not necessarily as a proposal. I'm not particularly familiar with this codebase, so if there's some other mechanism for managing the cache that should be triggered on these updates, that's something I'm curious about.

lb- commented 11 months ago

Does updating the image renditions make any difference?

https://docs.wagtail.org/en/latest/reference/management_commands.html#wagtail-update-image-renditions

./manage.py wagtail_update_image_renditions
zerolab commented 11 months ago

@lb- it should, however that is quite the nuclear option and we should clear just the renditions for the image one changes the focal point for

lb- commented 11 months ago

Yep. That's fair.

Temidayo32 commented 10 months ago

Note on the preview page that the image's focal point still shows the old value

@krieghan Can you clarify what you mean by the preview page?

I have attempted reproducing the error. This is what I have tried:

Here is the old focal point: msedge_SmK4t1wkZ1

Here is the new focal point:

McSSa7R3zJ

You can provide more information if I am missing something in reproducing the error. Thanks.

krieghan commented 10 months ago

I'm specifically talking about the "preview" option in the page edit admin:

image

When I update the image focal point, the page preview displays with the old focal point. I don't know if anyone else has reproduced this issue, but it seems like a general bug.

Temidayo32 commented 10 months ago

@krieghan Oh, I see. Let me check that

Temidayo32 commented 10 months ago

@krieghan Can I understand you better? Do you mean the focal point (the green box) would appear on the image on the preview? Look at what I have here. The full image appears on preview regardless of a defined focal point area

msedge_GnhmhANk98

krieghan commented 10 months ago

For starters, I've been viewing the preview in a separate page (the far right link on that toolbar). The other thing is that the focal point is only relevant if the full image is larger than the image area on the page.

Temidayo32 commented 10 months ago

Oh, okay. Thanks.