Presave hook is called twice on entity creation

Created on 4 May 2023, almost 2 years 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

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

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 almost 2 years 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().

  • Status changed to Closed: cannot reproduce 2 months ago
Production build 0.71.5 2024