-
-
Notifications
You must be signed in to change notification settings - Fork 867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #857 - fix on put when both @id and id are present #877
Conversation
c84c974
to
1caa29c
Compare
@@ -28,12 +28,12 @@ | |||
public function denormalize($data, $class, $format = null, array $context = []) | |||
{ | |||
// Avoid issues with proxies if we populated the object | |||
if (isset($data['id']) && !isset($context['object_to_populate'])) { | |||
if (isset($data['@id']) && !isset($context['object_to_populate'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet already exists in the JSON-LD normalizer: https://github.com/api-platform/core/blob/master/src/JsonLd/Serializer/ItemNormalizer.php#L93
@id
is specific to JSON-LD, so it should not be here. However id
can contain an IRI too (when not using JSON-LD). So it should be kept. I guess it's a priority problem, in https://github.com/api-platform/core/blob/master/src/JsonLd/Serializer/ItemNormalizer.php#L101 the call to the parent method should be done before.
769085e
to
d17eb1f
Compare
@dunglas This is now working but i'm not sure about the fix, since I don't think it's in the same scope then the iriConverter is, clearly this is not an IRI, do you have any thing in mind that would be better ? EDIT: it's not the right fix ;) |
4962c1f
to
ae817d5
Compare
9c730f2
to
d644132
Compare
Again, maybe not the best fixes, but better than before since it's working and it does not break anything. |
@@ -32,8 +32,7 @@ public function denormalize($data, $class, $format = null, array $context = []) | |||
if (isset($context['api_allow_update']) && true !== $context['api_allow_update']) { | |||
throw new InvalidArgumentException('Update is not allowed for this operation.'); | |||
} | |||
|
|||
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['id'], $context + ['fetch_data' => false]); | |||
$context['object_to_populate'] = $this->iriConverter->getItemFromIri(is_int($data['id']) ? $this->iriConverter->getIriFromResourceClass($context['resource_class']).'/'.$data['id'] : $data['id'], $context + ['fetch_data' => false]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id can be from other types (uuid are strings for instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What could I do about that ?
Edit: Was thinking about try catching and doing the getIriFromResourceClass, WDYT @dunglas ?
4016c69
to
00b4d93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When test will be green.
00b4d93
to
3cfd553
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments for some nitpicking changes, 👍 overall :)
* @ApiResource(attributes={ | ||
* "normalization_context"={"groups"={"related_output", "output"}}, | ||
* "denormalization_context"={"groups"={"related_input", "input"}} | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useless extra line
/** | ||
* @return int | ||
*/ | ||
public function getId() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't a return typehint more suitable here and the other places in the same class?
"name": "My Dummy", | ||
"alias": "My alias" | ||
} | ||
""" | ||
|
||
Scenario: Create a resource with relation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the scenario summary (same for all below)...
The fix is simple: We must not support embedded relations with So I'm -1 since this is the wrong fix. /cc @api-platform/core-team |
@teohhanhui the issue here isn't with embedded relations but using raw ids instead of IRIs in raw JSON. Not sure we should support that too. |
What is the issue with deserializing using a raw id property (or composite id represented as separate properties)? I think it should be supported. |
3cfd553
to
6244be0
Compare
@teohhanhui updated |
try { | ||
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['id'], $context + ['fetch_data' => false]); | ||
} catch (InvalidArgumentException $e) { | ||
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($this->iriConverter->getIriFromResourceClass($context['resource_class']).'/'.$data['id'], $context + ['fetch_data' => false]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this going to work with composite identifiers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also this is hardcoded to use the property "id"? 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@teohhanhui @dunglas do we want to support composite identifiers ?
5402a00
to
a76f79f
Compare
ping @teohhanhui @dunglas modification done, WDYT ? |
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['id'], $context + ['fetch_data' => false]); | ||
} catch (InvalidArgumentException $e) { | ||
foreach ($this->propertyNameCollectionFactory->create($context['resource_class'], $context) as $propertyName) { | ||
if (true === $this->propertyMetadataFactory->create($context['resource_class'], $propertyName)->isIdentifier()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't support yet composite identifiers, you can break after the first find. Or you can add support for composite identifiers :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for the composite support :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now we should bug fix this and then add that feature ?
$identifier = $propertyName; | ||
} | ||
} | ||
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($this->iriConverter->getIriFromResourceClass($context['resource_class']).'/'.$data[$identifier], $context + ['fetch_data' => false]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use sprintf
here for clarity.
c1a931a
to
0cb7e08
Compare
@api-platform/core-team is everyone OK to merge this one too? I want to publish a bugfix release today. |
0cb7e08
to
137a36e
Compare
Thanks @Simperfit! |
fix api-platform#857 - fix on put when both @id and id are present
Add an non-regression test and modify the comportement of itemNormalizer