Broken NamedBlobImage in edit-tile

I have a problem when I try to edit a Tile with a NamedBlobImage. The code is like this:

tile.py

class IDestaqueTile(model.Schema):
    image = NamedBlobImage(
        title = u"Image",
        required = True
    )

class DestaqueTile(tiles.PersistentTile):
    """PersistentTile"""

configure.zcml

<plone:tile
    name="example.destaque"
    title="Destaque"
    add_permission="cmf.ModifyPortalContent"
    class=".tile.DestaqueTile"
    for="*"
    permission="zope.Public"
    schema=".tile.IDestaqueTile"
    template="templates/destaque.pt"
    layer="example.interfaces.IExampleSpecific"
    />

Pretty strait forward so far. I can edit tiles using the @@edit-tile view.
eg.:@@edit-tile/example.detaque/name_of_the_tile

I can upload the image to this tile without problems. When editing the tile with a image already upload I get the standard plone upload widget asking if I want to keep the image or override it.

Captura de tela de 2020-02-28 13-30-19

The problem is that if I let checked keep existing image and hit save the image is erased with any errors or warning. When I choose to replace the image everything works as expected.

This behavior means that the user will need to resend the image every time they try to edit this tile, which can be problematic.

Is this a known bug? Does anyone have any ideias?

Apologies if this is unrelated, but I remember another issue we had with Image fields in tiles. We are also using persistent tiles, no data is lost when editing the (Persistent) tile, but the download link to retrieve the already uploaded image does not not work. This is with Plone 5.1.6 & plone.app.mosaic 2.1.1) My colleague @mauritsvanrees couldn't find an easy solution back then.

Which Plone version are you using @lyralemos ? Are you using plone.app.mosaic or another/ custom tile edit/rendering solution?

IIRC when you edit a persistent tile you have created, there should be some UUID/id reference in the url to the edit tile so that the edit-tile view can load the data from an annotation stored on the context.

'ephemeral' non persistent tiles get their data from the url_params or from the context (like most tiles in plone.app.standardtiles, they are proxies to data on the context).

Hi @fredvd, i'm using Plone 5.2.1, without Mosaic, just simple persistent tiles.

I've actually managed to find the source of my problem, I'm opening a issue right now.

To be short, the problem is that when the tile is saved, the extractData method here:

Returns a dict like this:

{'image': <NOT_CHANGED>}

Then, when applying changes to the dataManager the original value is lost

One solution would be to merge the current data with the new one, like this:

form.applyChanges(self, new_data, data)
for group in self.groups:
    form.applyChanges(group, new_data, data)
    
# Merge new data with the current to avoid removing images
current_data = self.getContent()
current_data.update(new_data)
    
dataManager.set(current_data)

This way no data will be lost while editing.

Here is the issue:

I spent a lot of time a few years ago trying to find a workaround … without success.

Lately, Add images and then use a related items (or similar) field to 'link to the image'.
Some of my 'trying' is still on GitHub, I doubt it is of any use, but just in case: https://github.com/espenmn/medialog.tiles/blob/master/medialog/tiles/browser/configure.zcml

Thanks @espenmn.

I'm hoping someone with more knowledge than I in the p.a.tiles package to comment my proposed solution. Should I just submit an PR and wait for some response?

Unfortunately, I can not remember too much about 'this problem'.

But, if I remember right, the logo 'upload' of the site control panel had the same 'problem' before. Maybe it is worth looking at how it was solved there (?)

The latest bug with the logo & site controlpanel I remember was that the file field/widget would cause a zodb write when you opened the website control panel, causing plone.protect to wake up @mauritsvanrees fixed that one iirc.

Okay, a few time has passed since the issue was post, so today a submitted a PR:

I've been running this code without issues in production for more than two months now.
My use case is not the greatest because I only use a few simple tiles without mosaic, but it's somenting.

Hope some can review it.

Cheers.

1 Like

Plone Foundation Code of Conduct