Call to a member function getTranslation() on null in ContentEntityBase

Created on 24 January 2020, over 4 years ago
Updated 5 March 2024, 3 months ago

Problem/Motivation

Trying to migrate some node revisions using the drupal migration system (Drupal 8.8), I am getting the following error:

Call to a member function getTranslation() on null in Drupal\Core\Entity\ContentEntityBase->hasTranslationChanges

It seems that it cannot get the original entity and call the function getTranslation() on it. So, possibly, a check for the existence of the original entity, could avoid this error, although the root of the problem may be that an original entity should always exist and it should never be null (then there might be a problem with the migrated content).

Steps to reproduce

Migrating an updated entity that exists in the destination:

  1. Generate a node complete migration for 2 node types from a Drupal 7 source database.
  2. Run initial node complete migrations from Drupal 7 source database.
  3. Create a new revision on node type #1 in the Drupal 7 source database.
  4. Create a new revision on node type #2 in the destination database with the same revision id as used in the Drupal 7 source database (simulating auto-incrementing sequences from the same state).
  5. Run node complete migration for node type #1 from Drupal 7 source database.

Migrating a new entity that exists in the destination:

  1. Generate a node complete migration for 2 node types from a Drupal 7 source database.
  2. Run initial node complete migrations from Drupal 7 source database.
  3. Create a new node of node type #1 in the Drupal 7 source database.
  4. Create a new revision on node type #2 in the destination database with the same revision id as used in the Drupal 7 source database (simulating auto-incrementing sequences from the same state).
  5. Run node complete migration for node type #1 from Drupal 7 source database.

Proposed resolution

1. Check whether the entity loaded by revision id found in the destination database has the same destination entity id.
2. If not, if the destination entity id exists in the destination database, create a new revision.
3. If the destination entity id does not exist in the destination database, ensure that a new entity is created with a new revision.
4. Throw a migrate exception when a translation is not found, but expected.

Remaining tasks

The current patch ignores the fatal error, but results in a caught error being thrown for some content but not all content being migrated.

- Figure out if the merge request approach works.
- Write kernel tests based on steps to reproduce.

User interface changes

No

API changes

TBD

Data model changes

No

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Migration 

Last updated about 5 hours ago

Created by

🇬🇷Greece MariaIoann

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024