Presave hook is called twice on creation of an entity instance

Created on 4 May 2023, over 1 year ago

Problem/Motivation

When creating a new entity using the EckEntity form, hook_entity_presave is called twice. This is a problem because some hook implementations may be resource-heavy or might have reasons why the logic should not be run twice

Steps to reproduce

Create an EckEntity type called Foo
Write a hook in a custom module called mymodule_foo_presave
Put a breakpoint or logging statement in the hook implementation
Use the EckEntity creation form to create an instance of foo
The breakpoint will be hit twice or the logging statement output twice.
The first time, the entity does not yet have an id. The second time, it does

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Postponed: needs info

Component

Code

Created by

🇬🇧United Kingdom hoegrammer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @hoegrammer
  • Status changed to Postponed: needs info over 1 year ago
  • 🇧🇪Belgium dieterholvoet Brussels

    I just tested this, following the steps as described, but I cannot reproduce this issue. Are you sure there isn't another module updating and re-saving the entity? Since you're able to set breakpoints you could check the call stack to know where exactly the two saves are coming from. One - the only one in my case - should come from Drupal\eck\Form\Entity\EckEntityForm::save().

Production build 0.71.5 2024