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] Repeatable field delete images on update operation #5728

Open
cod3rshotout opened this issue Dec 6, 2024 · 3 comments
Open

[Bug] Repeatable field delete images on update operation #5728

cod3rshotout opened this issue Dec 6, 2024 · 3 comments
Labels

Comments

@cod3rshotout
Copy link

Bug report

I'm using this repeatable field to handle a list of images:

   $multimedia_tab = __('backend/place.tabs.gallery');
    CRUD::field('gallery')
        ->label(__('backend/place.gallery.menu_title'))
        ->type('repeatable')
        ->tab($multimedia_tab)
        ->subfields([
            [
                'name'    => 'alt_text',
                'wrapper' => ['class' => 'form-group col-md-6'],
            ],
            [
                'name' => 'image',
                'label' => __('backend/place.gallery.image'),
                'type' => 'image',
                'withFiles' => [
                    'disk' => 'uploads',
                    'path' => 'places',
                ],
                'wrapper' => ['class' => 'form-group col-md-6'],
            ],
        ]);

What I did

I have created a record with a list of images, all of them was created succesfully. Then I have updated the entity without inserting any images (just text changes) and the images has gone.

What I expected to happen

When no new images are inserted then they shouldn't be removed.

What happened

The images was removed but I just updated a text field.

What I've already tried to fix it

If I change the type in "upload" all works well, but why?

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there?
yes.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

backpack/basset: 1.3.6
backpack/crud: 6.7.43
backpack/filemanager: 3.0.10
backpack/generators: v4.0.7
backpack/logmanager: v5.0.2
backpack/medialibrary-uploaders: 1.2.1
backpack/pagemanager: 3.3.2
backpack/permissionmanager: 7.2.1
backpack/pro: 2.2.29
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.15

Copy link

Based on the information provided in the knowledge sources, it appears that there is indeed a known issue with the image field type within a repeatable field in Backpack CRUD. This bug is similar to the one you're experiencing, where images are being deleted unexpectedly during update operations.

Several users have reported similar issues:

  1. In Github Issue #5549, a user reported that when updating a model with a repeatable field containing an image subfield, the image data was broken and files were deleted from the disk.

  2. Another user in Github Issue #5631 reported issues with replacing images in repeatable subfields after deleting previously selected images.

  3. In Github Issue #4366, it was reported that the repeatable field doesn't work properly with image field types.

The Backpack team is aware of these issues and is working on a major refactoring of the uploader functionality to address these and other uploader-related problems. As mentioned by a contributor in one of the issues:

"We are aware of some issues related with uploaders and we have already a big PR to update them. The PR is in testing phase. #5478" Github Issue #5549

As a temporary workaround, you mentioned that changing the field type from image to upload resolves the issue. This is consistent with the behavior reported by other users and might be a viable solution until the official fix is released.

Unfortunately, the knowledge sources don't provide a definitive explanation for why the upload type works while the image type doesn't in this context. It's likely related to how these different field types handle file management during update operations.

For now, it's recommended to:

  1. Use the upload field type instead of image within repeatable fields as a workaround.
  2. Keep your Backpack packages updated, as the fix for this issue is expected to be released in a future update.
  3. Monitor the Backpack CRUD GitHub repository for updates on the uploader refactoring pull request (Uploaders - Refactor and fixes #5478).

If you need a more immediate solution, you might want to consider creating a custom field type or overriding the update method in your CRUD controller to handle the image uploads manually. However, these approaches would require more advanced customization of Backpack.

ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️

Relevant sources:

Github Issue (open): [Bug] CRUD Repeatable field with sub field image. Use withFiles param path broken file after update model.
Github Issue (closed): [Bug] error on replacing repeatable subfield image when first saving it empty
Github Issue (closed): [Bug] Uploaded files cannot be deleted
Github Issue (closed): [Bug] Repeatable does not work with image field types
Github Issue (closed): Image field in repeatable
Github Issue (open): [Bug] Upload Field Inside Repeatable Field Not Working Correctly
Github Issue (closed): multiple_upload field doesn't allow delete in update view.
Github Issue (open): [Bug] Dropzone within repeatable not working correctly
Github Issue (closed): [Bug] "upload_multiple" field within subfields of a "relationship" field does not allow files to be deleted
Github Issue (open): [BUG] ValidUploadMultiple - False validation while updating
Github Issue (closed): [Bug] Multiple Upload does not select images after deleting all previous selected
Github Issue (open): [Bug] crud-api doesn't work properly with upload fields.
Github Issue (closed): [Bug] Multiple upload in a relationship does not work with Spatie/MediaLibrary
Github Issue (closed): [Bug] browse field looks messed up inside repeatable

@rezahmady
Copy link

I have same problem

@karandatwani92
Copy link
Contributor

Hey @cod3rshotout

Sorry for the inconvenience.

We are aware of similar uploader issues and have a PR ready to fix them. Unfortunately, this PR requires a breaking change. So, it will included in the upcoming Backpack v7.0, along with other fixes and features that require a breaking change. Hopefully, Backpack v7 will launch in January 2025.

You can help us by sharing your field definition and relationship code. If it differs from other reported issues, we'll put that to the test.

@karandatwani92 karandatwani92 added Bug and removed triage labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants