Importing revisioned webform config can cause 500 errors in some circumstances

Created on 17 February 2023, over 1 year ago
Updated 18 May 2023, over 1 year ago

Problem/Motivation

It is possible for a scenario to arise where the content entity ID or revision ID attached to a webform (and probably other config) does not correspond to an existing entity. This causes fatal errors on some pages that ultimately invoke Drupal\config_entity_revisions\ConfigEntityRevisionsControllerBase::createUpdateRevision(), such as the webform build page.

In my case I think this happened because of webform config referencing a revision being exported then imported on a remote environment where that revision did not exist. But it could happen in other situations as well, e.g. if a revision is deleted somehow.

It's also likely that this could cause a more subtle error where a webform would reference a revision not belonging to it.

Steps to reproduce

These steps to reproduce are to reproduce the error easily and differ from the config import way I mentioned above.

  1. Create a webform and add a revision
  2. Examine the webform's config and find the third_part_settings.webform_revisions key, e.g. with drush cget webform.webform.my_test_webform third_party_settings..webform_revisions.contentEntity_id.
  3. Delete the revision, e.g. with drush entity:delete config_entity_revisions 1 (but replace 1 with the revision ID if different)
  4. Try to visit the build tab for your webform - you will encounter a 500 error

The content of the error is:

Error: Call to a member function get() on null in Drupal\config_entity_revisions\ConfigEntityRevisionsControllerBase->createUpdateRevision() (line 206

Proposed resolution

This can be worked around by just adding a bit more defensive code to set the content and revision ID variables to NULL if the corresponding entity/revision can't be loaded. I'll attach an MR for that shortly.

With this workaround webforms still lose their revisions when imported. I think this is an edge case though and I don't see a simple way to resolve that. Seems like it would require syncing revisions between environments somehow which seems pretty out of scope for this module. Maybe you have a better idea though.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Dylan Donkersgoed London, Ontario

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

Comments & Activities

Production build 0.71.5 2024