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.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3202244-11.patch | 2.9 KB | empesan |
| #10 | 3202244-10.patch | 1.14 KB | andypost |
Issue fork default_content-3202244
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
Comment #2
omarlopesinoComment #4
bgilhome commentedHere's a patch if anyone's interested.
Comment #5
bgilhome commentedI 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().
Comment #6
rajab natshah+1 for #5
Having the same issue in 2 cases when doing partial export.
Comment #7
omarlopesinoAgree 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.
Comment #8
neclimdulCode worked perfect for me. Only thing I could say is missing is a test showing the failure and proving its fixed.
Comment #9
andypostYes, not clear which entity does not implement this interface and why it's serialized
Comment #10
andypostIf there's reason to process broader types there's
FieldableEntityInterfacewhich can be used as the argument type for\Drupal\default_content\Normalizer\ContentEntityNormalizer::addDependency()The method using only 2 methods of
EntityInterfaceso here's a patchComment #11
empesan commentedSometimes 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
Comment #12
berdirMerge 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.
Comment #14
vensiresThank you @berdir for your comment. I have updated MR!7 with the changes from patch #11 while still keeping the ContentEntityInterface requirement.
Comment #15
berdirThanks, one more review.