Problem/Motivation

When exporting a node, I receive the error:

TypeError: Argument 1 passed to Drupal\default_content\Normalizer\ContentEntityNormalizer::addDependency() must implement interface Drupal\Core\Entity\ContentEntityInterface, null given

Is it true that in the first place there shouldn't be stale entity references, but I don't want to know what entity I've lost, I just want to export the actual entity.

Steps to reproduce

Having default content imported in the site and trying to export content that has stale links (pointing to unexisting entities), using the command 'drush default-content:export-references'

Proposed resolution

Checking the loaded URI entity exists after loading it.

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

omarlopesino created an issue. See original summary.

omarlopesino’s picture

Issue summary: View changes

bgilhome’s picture

Here's a patch if anyone's interested.

bgilhome’s picture

StatusFileSize
new857 bytes
new967 bytes

I think we need to check if the link target implements ContentEntityInterface not just EntityInterface (e.g. if it references a config entity like a view or webform - we don't want to export that), to avoid an error re: argument type for ContentEntityNormalizer->addDependency().

rajab natshah’s picture

+1 for #5
Having the same issue in 2 cases when doing partial export.

  • On install for a profile with default content.
  • On install for a module with default content.
omarlopesino’s picture

Status: Active » Needs review

Agree with @bgilhome that we only need to support content entities, as all the normalizer supports only content entities. I've updated the MR with that fix.

Moving to needs review, if you think the solution is tested enough we can move it straight to RTBC.

neclimdul’s picture

Code worked perfect for me. Only thing I could say is missing is a test showing the failure and proving its fixed.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Yes, not clear which entity does not implement this interface and why it's serialized

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.14 KB

If there's reason to process broader types there's FieldableEntityInterface which can be used as the argument type for \Drupal\default_content\Normalizer\ContentEntityNormalizer::addDependency()

The method using only 2 methods of EntityInterface so here's a patch

empesan’s picture

StatusFileSize
new2.9 KB

Sometimes exporting of entities resulted in the following error:

TypeError: Drupal\default_content\Normalizer\ContentEntityNormalizer::addDependency(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /app/modules/contrib/default_content/src/Normalizer/ContentEntityNormalizer.php on line 453 in /app/modules/contrib/default_content/src/Normalizer/ContentEntityNormalizer.php on line 482 #0 /app/modules/contrib/default_content/src/Normalizer/ContentEntityNormalizer.php(453): Drupal\default_content\Normalizer\ContentEntityNormalizer->addDependency(NULL)

so I rerolled the latest patch and added a double check to assert that the argument being sent to addDependency() function is always an EntityInterface

berdir’s picture

Status: Needs review » Needs work

Merge request wasn't updated with recent patches, and I disagree with the API change to EntityInterface. default_content is about content entities. There's no need to expand that.

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

vensires’s picture

Status: Needs work » Needs review

Thank you @berdir for your comment. I have updated MR!7 with the changes from patch #11 while still keeping the ContentEntityInterface requirement.

berdir’s picture

Status: Needs review » Needs work

Thanks, one more review.