Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291529

Translated field denormalization creates duplicate values

$
0
0

Problem/Motivation

To reproduce:

1. Enable rest, hal, language, content_translation on a standard profile.
2. Enable a second language (German) and make the node type "page" translatable with all fields.
3. Save the attached JSON text file (generated by NodeHalJsonCookieTranslationsTest).
4. Enter the Drupal console and use the following commands:


$serializer = \Drupal::service('serializer');
$data = $serializer->decode(file_get_contents('JSON_FILE'), 'hal_json');
$node = $serializer->denormalize($data, 'Drupal\node\Entity\Node', 'hal_json');

The deserialized node's translation contains values for all "default" items (status, sticky, created, changed, langcode, etc.)

print count($node->changed); // 1
print count($node->getTranslation('de')->changed); // 2

The duplicates increase each time the node is normalized and denormalized.


$node = $serializer->denormalize($serializer->normalize($node, 'hal_json'), 'Drupal\node\Entity\Node', 'hal_json');
print count($node->changed); // 1
print count($node->getTranslation('de')->changed); // 3
$node = $serializer->denormalize($serializer->normalize($node, 'hal_json'), 'Drupal\node\Entity\Node', 'hal_json');
$node = $serializer->denormalize($serializer->normalize($node, 'hal_json'), 'Drupal\node\Entity\Node', 'hal_json');
print count($node->changed); // 1
print count($node->getTranslation('de')->changed); // 5

This looks like a bug in the field denormalization which causes it fail to properly clear default values.

Tested on 8.5.x and 8.3.7. This is causing test failures in #2135829: [PP-1] EntityResource: translations support.

Proposed resolution

Avoid the field value duplication.

Remaining tasks

  1. Get patch to green.
  2. Review.
  3. Commit.

User interface changes

None.

API changes

None.

Data model changes

None.


Viewing all articles
Browse latest Browse all 291529

Trending Articles