Integrity constraint violation when trying to add multiple blocks in a complex IEF field

Created on 19 September 2024, 2 months ago

Problem/Motivation

We're using IEF with a reference to custom block entities, with different block types. This used to work fine, but recently it's broken on multiple sites -- not exactly sure when it started breaking, perhaps with the switch to RAT?

You have to add one reference at a time, or you get an error.

Steps to reproduce

1. Create a custom block type with a media field and a body field.
2. Add an entity reference field to a content type that is configured to reference the new block type, unlimited cardinality.
3. Set the field widget to IEF, allow adding new or reusing existing.

4. Create a node of this content type.
5. Create a new block in this field, and save it.
6. Attempt to create another block in this field -- note that you see the same image and text in the edit form -- I think the problem is that the form state is not getting cleared out when you open IEF a second time with a different related entity.

7.Try to save -- whitescreen with Integrity constraint violation.

Proposed resolution

Clear out form state every time the child form is opened.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

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

Comments & Activities

  • Issue created by @freelock
  • πŸ‡ΊπŸ‡ΈUnited States kwiseman

    I think I'm experiencing this issue too. We're using IEF to only allow creating new referenced content (hopefully) without duplicates, but when I try to add more than one node simultaneously, I get an integrity constraint violation. Here's the text from my white screen:

    Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '4878388b-8fb8-4325-a3ca-6e8e2a73fd04' for key 'node_field__uuid__value': INSERT INTO "node" ("vid", "type", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => resource [:db_insert_placeholder_2] => 4878388b-8fb8-4325-a3ca-6e8e2a73fd04 [:db_insert_placeholder_3] => en ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Production build 0.71.5 2024