Scheduler form alter breaks creation of new taxonomies (and potentially other bundle entities)

Created on 5 November 2024, 2 months ago

Problem/Motivation

The function _scheduler_form_entity_type_submit has the following line:

$form_display = $display_repository->getFormDisplay($entity_type_id, $bundle_id, $display_mode);

And then calls $form_display->someChainableStuff()->save() a bunch of times below that. However, getFormDisplay() will return a newly created config entity because nothing existed yet. It seems that calling save multiple times on said newly created entity will lead to the following exception being thrown:

Drupal\Core\Config\ConfigDuplicateUUIDException: Attempt to save a configuration entity 'taxonomy_term.testing.default' with UUID '' when this entity already exists with UUID '9b85d17b-68ab-49cb-9f74-71e157da4287' in Drupal\Core\Config\Entity\ConfigEntityBase->preSave() (line 318 of core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php).

This is because the initial entity has no UUID, gets one on the first save and then you try to reset that to NULL by saving the initially created entity again.

You could argue it's a core bug and that the UUID field needs to be populated after the first save. But the problem definitely manifests itself in this module.

Steps to reproduce

  1. Enable Scheduler for taxonomy
  2. Leave both fields unchecked when creating a new taxonomy
  3. Witness a WSOD

Proposed resolution

Check the entity for isNew() and adjust accordingly or only save the display once at the bottom of the submit handler.

Remaining tasks

  1. Test for failure
  2. Fix failure
  3. See test go green

User interface changes

/

API changes

/

Data model changes

/

🐛 Bug report
Status

Active

Version

2.1

Component

Code

Created by

🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

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

Comments & Activities

Production build 0.71.5 2024