Problem/Motivation

Got this error while migrating webform submission records

[error]  Error: Call to a member function invokeHandlers() on null in Drupal\webform\Entity\WebformSubmission::preCreate() 
(line 835 of /app/web/modules/contrib/webform/src/Entity/WebformSubmission.php) #0 /app/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(87): Drupal\webform\Entity\WebformSubmission::preCreate()
#1 /app/web/modules/contrib/webform/src/WebformSubmissionStorage.php(932): Drupal\Core\Entity\ContentEntityStorageBase->create()

This error happens when the webform for the particular submission record no longer exists.

Proposed resolution

To fix this issue, at prepareRow function for D7WebformSubmission.php, check nid of the webform_submission record actually exist in the drupal, if it doesn't exist assign NULL for webform_id field

Also tweak d7_webform_submission.yml to skip if webform_id field is NULL

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cyoon84 created an issue. See original summary.

cyoon84’s picture

Status: Patch (to be ported) » Needs work
cyoon84’s picture

solideogloria made their first commit to this issue’s fork.

solideogloria’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Assigned: cyoon84 » Unassigned
Priority: Major » Normal
Status: Needs work » Needs review

I created a merge request that incorporates #3, because #3 didn't apply to dev. However, instead of a straight reroll, I changed the entityQuery to use count() and check if the count > 0, rather than loading the node's actual data.

I ran a migration with the changes, and it works and fixes the error. Please review.

danflanagan8’s picture

I solved this entirely in the yaml with the help of Migrate Conditions.

  _skip_if_webform_not_exists:
    plugin: skip_on_condition
    source: webform_id
    method: row
    condition:
      plugin: not:entity_exists
      entity_type: webform

You could probably do it with just core process plugins like so:

_webform_exists:
  plugin: entity_exists
  entity_type: webform
  source: webform_id
_skip_if_webform_not_exists:
  plugin: skip_on_empty
  method: row
  source: '@_webform_exists'

but that's un-tested.

solideogloria’s picture

The module shouldn't be so hard to use that you have to add another module for something like that. I think it makes more sense for the submission migration to automatically check if a webform exists before trying to migrate a submission.

danflanagan8’s picture

The module assumes that you're migrating all the webforms, which is a reasonable assumption, especially given that when you delete a webform through the UI all the submissions get deleted. I have a case now where we didn't migrate closed webforms. That's a special case that not unreasonable requires some extra work.

Also, I showed how the skip could be done with core process plugins. I just think it looks nicer with the contrib ones. A migration_lookup could be done in place of the entity_exists call too. entity_exists is in core but it's not actually used in core. migration_lookup is more familiar.

_webform_lookup:
  plugin: migration_lookup
  source: nid # I initially had webform_id here but I think nid is the sourceid
  migration: d7_webform # or whatever
  no_stub: true
_skip_if_webform_not_exists:
  plugin: skip_on_empty
  method: row
  source: '@_webform_lookup'
solideogloria’s picture

It would need to be this (just add the webform_id field):

  _webform_lookup:
    plugin: migration_lookup
    source: nid
    migration: d7_webform
    no_stub: true
  _skip_if_webform_not_exists:
    plugin: skip_on_empty
    method: row
    source: '@_webform_lookup'
  webform_id: webform_id

Then it works.