AssertionError when webform is submitted that doesn't record submissions

Created on 21 June 2023, over 1 year ago

Problem/Motivation

We've created a webform that specifically doesn't save submissions to the database; it uses Handlers to interact with external services only.

When a submission is created, it invokes the WebformSubmissionStorage::doPostSave method, which in turn invokes ancestor method EntityStorageBase::doPostSave. This invokes hook_entity_insert or hook_entity_update, which calls content_sync_entity_update.

The entity that just got created or updated is reloaded from the database so Content Sync can process it. But there's a catch; since the webform submission entity was never saved to the database, it has a NULL ID, which produces the following stack trace.

NOTICE: PHP message: AssertionError: Cannot load the "webform_submission" entity with NULL ID. in /data/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php on line 295 #0 /data/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(295): assert()
#1 /data/web/modules/contrib/content_sync/content_sync.module(215): Drupal\Core\Entity\EntityStorageBase->load()
#2 /data/web/modules/contrib/content_sync/content_sync.module(235): content_sync_entity_update()
#3 [internal function]: content_sync_entity_insert()
#4 /data/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(426): call_user_func_array()
#5 /data/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()
#6 /data/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(433): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#7 /data/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(251): Drupal\Core\Extension\ModuleHandler->invokeAll()
#8 /data/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(900): Drupal\Core\Entity\EntityStorageBase->invokeHook()
#9 /data/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(598): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook()
#10 /data/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(781): Drupal\Core\Entity\EntityStorageBase->doPostSave()
#11 /data/web/modules/contrib/webform/src/WebformSubmissionStorage.php(1025): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave()
#12 /data/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(523): Drupal\webform\WebformSubmissionStorage->doPostSave()
#13 /data/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(804): Drupal\Core\Entity\EntityStorageBase->save()
#14 /data/web/modules/contrib/webform/src/WebformSubmissionStorage.php(983): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()
#15 /data/web/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\webform\WebformSubmissionStorage->save()
#16 /data/web/modules/contrib/webform/src/Entity/WebformSubmission.php(901): Drupal\Core\Entity\EntityBase->save()
#17 /data/web/modules/contrib/webform/src/WebformSubmissionForm.php(1995): Drupal\webform\Entity\WebformSubmission->save()
...

To some extent this relates to https://www.drupal.org/project/content_sync/issues/3279434; it might be a good idea to exclude webform submissions from Content Sync by default.

Steps to reproduce

  1. Install Content Sync and Webform
  2. Create a webform that doesn't save submissions
  3. Submit the webform

Proposed resolution

Add a check to content_sync_entity_update that detects entities with a NULL ID. If it finds one, it doesn't attempt to reload the entity, and skips processing it.

Remaining tasks

  1. Add said check to update hook

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇦🇺Australia geoffreyr

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

Comments & Activities

Production build 0.71.5 2024