Skip to content

Commit 52855fa

Browse files
committed
Unset ID before calling parent denormalizer
1 parent 2f5e491 commit 52855fa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Serializer/ItemNormalizer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
6868
}
6969
}
7070

71+
// See https://github.com/api-platform/core/pull/7270 - id may be an allowed attribute due to being added in the
72+
// overridden getAllowedAttributes below, in order to allow updating a nested item via ID. But in this case it
73+
// may not "really" be an allowed attribute, ie we don't want to actually use it in denormalization. In this
74+
// scenario it will not be present in parent::getAllowedAttributes
75+
if (isset($data['id'], $context['resource_class'])) {
76+
$parentAllowedAttributes = parent::getAllowedAttributes($class, $context, true);
77+
if (is_array($parentAllowedAttributes) && !in_array('id', $parentAllowedAttributes)) {
78+
unset($data['id']);
79+
}
80+
}
81+
7182
return parent::denormalize($data, $class, $format, $context);
7283
}
7384

0 commit comments

Comments
 (0)