Files field empty on panel, but not on content, after programatic update

Hello,

v4.5 here.

I’ve been programmatically updating files fields, and I am having a brain-breaking problem.

I have pages with a files field that:

  • Shows visually EMPTY in the panel.
  • Is NOT EMPTY in the content file.
  • Seems NOT EMPTY when programmatically checking it.
  • The file it points at seems to exist when programmatically checking it.

This is the relevant bits of the blueprint declaration:

title: Publication
(...)
fields:
  cover:
    label: Cover Image
    type: files
    multiple: false 
    size: medium
    layout: cards
    translate: false
    uploads: image

This is an example of how I updated the cover field:

  $p->update([
      "cover" => Data::encode([$filename], "yaml"),
  ]);

This is the relevant bits of content file for one of these pages:

Title: 1979 abril-maig

----

Cover: - file://ThGiumUCdevzznrJ

This is my debugging code:

  $uuid = $p->cover()->yaml();
  try {
      $file = $p->cover()->toFile();

      if ($file && $file->exists()) {
          echo "✅ Cover file exists: “{$file->filename()}” (UUID: {$uuid[0]})<br>";
      } else {
          echo "❌ toFile() returned null (invalid UUID or no cover set) – stored value: “{$uuid[0]}”<br>";
      }
  }

This is the output for this particular page:

1979 abril-maig

✅ Cover file exists: “1979-guino-galeria-trece-web.jpg” (UUID: file://ThGiumUCdevzznrJ)

And this is how it looks in the panel, notice the apparently empty “cover” files field:

If I click on the field, the image shows with the right title:

Aaand, this happens in a LOT of these pages.

Help? :sos_button: Thanks :slight_smile:

I ran some additional tests.

Apparently, if I select the file manually in the panel, then the content file shows:

Cover: - file://R0GMZtJq4lC2X9Sq

Which does NOT match the UUIID shown before which was:

✅ Cover file exists: “1979-guino-galeria-trece-web.jpg” (UUID: file://ThGiumUCdevzznrJ)

But how could this be? Considering I was extracting that UUID using:

$uuid = $p->cover()->yaml();
$file = $p->cover()->toFile();
echo "✅ Cover file exists: “{$file->filename()}” (UUID: {$uuid[0]})<br>";

And now it says:

✅ Cover file exists: “1979-guino-galeria-trece-web.jpg” (UUID: file://R0GMZtJq4lC2X9Sq)

Even more confused now.

I guess R0GMZtJq4lC2X9Sq is then the correct uuid. Not quite clear where the other one comes from, particularly since the code to update the page you posted above is very rudimentary. Does the first UUID ThGiumUCdevzznrJ exist anywhere?