PrimitiveDataNormalizer invokes undefined method getParent

Created on 21 March 2019, about 6 years ago
Updated 2 February 2023, over 2 years ago

\Drupal\Core\TypedData\PrimitiveInterface can no longer be normalized. The normalize method of \Drupal\serialization\Normalizer\PrimitiveDataNormalizer calls "getParent" on an object which doesn't even have that method.

  public function normalize($object, $format = NULL, array $context = []) {
    $parent = $object->getParent();
    if ($parent instanceof FieldItemInterface && $object->getValue()) {
      $serialized_property_names = $this->getCustomSerializedPropertyNames($parent);
      if (in_array($object->getName(), $serialized_property_names, TRUE)) {
        return unserialize($object->getValue());
      }
    }

I added PrimitiveInterface to an object and attempted to normalize it and my test crashed.

Error : Call to undefined method Drupal\commerce_order\Adjustment::getParent()
 /Users/mglaman/Drupal/sites/commerce2x/web/core/modules/serialization/src/Normalizer/PrimitiveDataNormalizer.php:24
 /Users/mglaman/Drupal/sites/commerce2x/vendor/symfony/serializer/Serializer.php:143
 /Users/mglaman/Drupal/sites/commerce2x/web/modules/contrib/commerce/modules/order/tests/src/Kernel/AdjustmentItemSerializationTest.php:47
πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Typed dataΒ  β†’

Last updated 23 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΉAustria @fago
Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

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.71.5 2024