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

Double calls of updateFluentActions lead to RuntimeException #888

Open
2 tasks done
moritz-sauer-13 opened this issue Sep 12, 2024 · 2 comments
Open
2 tasks done

Comments

@moritz-sauer-13
Copy link

moritz-sauer-13 commented Sep 12, 2024

Module version(s) affected

^7

Description

Description:
When editing a page in a grid field, the problem occurs that the updateFluentActions() method is called twice. This happens both from the FluentSiteTreeExtension and from the FluentGridFieldExtension.

This double call results in the clearFluent field and other fields from the corresponding trait being present more than once. This causes a RuntimeException to occur when saving.

Steps for reproduction:

  1. Edit a page in a grid field in a Model Admin
  2. Saving/Publishing the page.

Expected behavior:
updateFluentActions() should only be called once to avoid duplicate field definitions and the resulting exception.

Actual behavior:
updateFluentActions() is called twice, resulting in duplicate definition of fields and a RuntimeException.

Error Message:

[Emergency] Uncaught RuntimeException: SilverStripe\Forms\{closure}() I noticed that a field called 'action_clearFluent' appears twice in your 'SilverStripe\Forms\Form' form called 'ItemEditForm'
POST /admin/offers/OfferPage/EditForm/field/OfferPage/item/55/ItemEditForm

Line 165 in /var/www/ss_project_web/vendor/silverstripe/framework/src/Forms/FieldList.php

How to reproduce

Model Admin:

private static $managed_models = [
      OfferPage::class,
];

FluentAdminTrait - updateFluentActions():

$moreOptions->push(
    FormAction::create(
        'clearFluent',
        _t(
            __TRAIT__ . '.Label_clearFluent',
            "Clear from all except '{title}'",
            [
                'title' => $locale->getTitle()
            ]
        )
    )->addExtraClass('btn-secondary')
);

Possible Solution

No response

Additional Context

No response

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
@tractorcow
Copy link
Collaborator

When editing a page in a grid field, the problem occurs that the updateFluentActions() method is called twice. This happens both from the FluentSiteTreeExtension and from the FluentGridFieldExtension.

I think I've had this issue before. I ended up solving it by just using a basic model, not a sitetree, which isn't really a reasonable workaround.

Suggested fix is to make the updateFluentAction() idempotent so that it safely can be called multiple times on the same action set.

@moritz-sauer-13
Copy link
Author

moritz-sauer-13 commented Sep 13, 2024

I have now temporarily written a patch to call the function in the gridfield extension only if the form action is not one of the corresponding model admin.
Not a nice solution either, but it works for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants