filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.08k stars 2.83k forks source link

Translatable resource with media bug #7591

Closed anaseqal closed 10 months ago

anaseqal commented 1 year ago

Package

filament/spatie-laravel-translatable-plugin

Package Version

v3.0.13

Laravel Version

v10.18.0

Livewire Version

v3.0.0-beta.8

PHP Version

PHP 8.2.8

Problem description

Editing translatable resource image throw exception:

Call to a member function hasGeneratedConversion() on null

Even if no conversion defined, there is still an error:

Call to a member function getAttributeValue() on null

Expected behavior

Edit image(s) without throwing errors

Steps to reproduce

  1. create a new customer and upload an image.
  2. edit the customer and change the image then click save changes

image

Reproduction repository

https://github.com/anaseqal/filament3-media-translation

Relevant log output

No response

AlexanderFalkenberg commented 1 year ago

Having the same issue.

AxelDeneu commented 1 year ago

Same here

elnurxf commented 1 year ago

One more here. Stuck for hours to figure it out. :/

Saifallak commented 1 year ago

Same here

pieinn commented 1 year ago

Same issue issue

awcodes commented 1 year ago

Figured out the issue, not sure of how to resolve it though, @danharrin leaving this here for you to see what I'm seeing.

The issue is in the Translatable Plugin at Resources\Pages\EditRecord\Concerns\Translatable class.

When looping through the locales to save the record data is getting out of sync.

data in save() for 'en' loop: Screenshot 2023-08-26 at 2 59 26 PM

record in handleRecordUpdate(): Screenshot 2023-08-26 at 2 59 33 PM

All good to this point.

data in save() for 'es' loop: Screenshot 2023-08-26 at 2 59 37 PM

record in handleRecordUpdate(): Screenshot 2023-08-26 at 2 59 42 PM

Which means that when the 'es' handle record runs the 'media' state is [], which causes the FileUpload Plugin to delete the originally saved media item, resulting in it not existing when the state is refreshed after save.

atmonshi commented 1 year ago

@awcodes I reached similar thing and didnt know were to go from there I think it needed something like this to mearg the data https://github.com/filamentphp/filament/pull/7503/files

but the getState in the edit is not getting the relations (it merges the data for all local if it's not relation like spatie uploader) so I don't know where to handle the "merge" for the data

awcodes commented 1 year ago

The issue is that non translated fields don't seem to be honoring their state separately. Somehow the media field, in this example, is existing in two different states. One for each locale.

awcodes commented 1 year ago

You can see that the es loop is getting updated with the origin values of the en loop but it's like it always a step behind.

eroctra commented 1 year ago

same issue

PterodactylStore commented 1 year ago

same issue

danharrin commented 1 year ago

Please stop commenting if you have the "same issue", there are 👍 reactions for that. Try submitting a PR if you would like to be helpful.

pekka commented 1 year ago

To clarify the original problem description, this appears to also happen when the image field itself is not translatable. It is enough for the field to be inside a resource that HasTranslations (which I'd argue makes it a bit higher priority than "low").

Only workaround I can see at this point (for anyone under pressure to use spatie-translatable but also this field type RIGHT NOW) is to have a separate, my_media table and resource, upload the images there, and connect them to the original resource using a relationship.

tahacankurt commented 1 year ago

And somehow when you add some validation to FileUpload such as image() etc.. its showing error but saving eventually.

robertorinaldi-dev commented 1 year ago

I had a very similar issue (it gave me an error when trying to get the file_size). Can you try if https://github.com/filamentphp/filament/pull/8432 solves the issue for you too?

mohamedsabil83 commented 11 months ago

This issue still occurred as @awcodes explained above. The #8432 seems doesn't fix it, or does it need extra steps @robertorinaldi-dev?

[
    'en' => [    
        'id' => 8,
        'position' => 5,
        'description' => '',
        'url' => '',
        'order_column' => 8,
        'created_at' => '2023-05-29T07:52:50.000000Z',
        'updated_at' => '2023-05-29T07:52:50.000000Z',
        'deleted_at' => null,
        'image' => [],,
    ],
    'ar' => [    
        'id' => 8,
        'position' => 5,
        'description' => '',
        'url' => '',
        'order_column' => 8,
        'created_at' => '2023-05-29T07:52:50.000000Z',
        'updated_at' => '2023-05-29T07:52:50.000000Z',
        'deleted_at' => null,
        'image' => [],,
    ],
]
mohamedsabil83 commented 11 months ago

@robertorinaldi-dev, the #8432 seems doesn't fix it. It still occurred, as @awcodes explained above. Do you think it needs any extra steps?

[
    'en' => [    
        'id' => 8,
        'position' => 5,
        'description' => '',
        'url' => '',
        'order_column' => 8,
        'created_at' => '2023-05-29T07:52:50.000000Z',
        'updated_at' => '2023-05-29T07:52:50.000000Z',
        'deleted_at' => null,
        'image' => [],
    ],
    'ar' => [    
        'id' => 8,
        'position' => 5,
        'description' => '',
        'url' => '',
        'order_column' => 8,
        'created_at' => '2023-05-29T07:52:50.000000Z',
        'updated_at' => '2023-05-29T07:52:50.000000Z',
        'deleted_at' => null,
        'image' => [],
    ],
]

Update

[!IMPORTANT] This happened in one of my projects using stancl/tenancy. For those who used that package, it happened on the tenant's site, not the central one. It may be related to changes in Livewire 3.

danharrin commented 10 months ago

Does not seem to be an issue any more, I've tried the reproduction repo.