Skip to content
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

3.1.11 - PUT does not work with ManyToMany deep nested relations #5587

Closed
mdieudonne opened this issue May 10, 2023 · 9 comments
Closed

3.1.11 - PUT does not work with ManyToMany deep nested relations #5587

mdieudonne opened this issue May 10, 2023 · 9 comments

Comments

@mdieudonne
Copy link

API Platform version(s) affected: 3.1.11

Description
PATCH does not work with ManyToMany deep nested relations.
But now neither does PUT standard_put: true in 3.1.11

Possible Solution
Revert latest changes made in ItemNormalizer.php

@mdieudonne mdieudonne changed the title 3.1.11 3.1.11 - PUT does not work with ManyToMany deep nested relations May 10, 2023
@soyuka
Copy link
Member

soyuka commented May 11, 2023

what because of ed4bca9 ?

or use standard_put: false?

@mdieudonne
Copy link
Author

mdieudonne commented May 11, 2023

what because of ed4bca9 ?

or use standard_put: false?

To be honest, it's challenging for me to pinpoint the exact cause.
I only have limited knowledge about Api P.

I retried with standard_put: false but it doesn't seem to change a thing in the response I have:
Payload:
image
Response:
image

For info, in my case : I do need partial updates ("standard_put" === "legacy PUT").

@mdieudonne
Copy link
Author

I also do have this behavior.
when submitting deep nested relations:

Payload:
image
Response:

3.1.11 + 'standard_put' => true || 'standard_put' => false
"Item not found for "/api/qual/qopse/fields/2123"."

3.1.10 + 'standard_put' => true || 'standard_put' => false
This is fine

@mdieudonne
Copy link
Author

@soyuka Now if I retry my tests but reverting back this line in ItemNormalizer.php

$iri = $this->iriConverter->getIriFromResource($context['resource_class'], UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => ['id' => $data['id']]]);

Then this is fine in 3.1.11 too

@soyuka
Copy link
Member

soyuka commented May 22, 2023

I tried to reproduce your issue without success, may you provide a reproducer?

@mdieudonne
Copy link
Author

@soyuka
As previously said, if I modified ItemNormalizer as below, it works:

// $uriVariables = $this->getContextUriVariables($data, $operation, $context);
// $iri = $this->iriConverter->getIriFromResource($context['resource_class'], UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => $uriVariables]);
$iri = $this->iriConverter->getIriFromResource($context['resource_class'], UrlGeneratorInterface::ABS_PATH, $operation, ['uri_variables' => ['id' => $data['id']]]);

I've added data dumps in getContextUriVariables as below:

    private function getContextUriVariables(array $data, $operation, array $context): array
    {
        dump('$context[\'uri_variables\']', $context['uri_variables']);
        dump('$data[\'id\']',$data['id']);
        if (!isset($context['uri_variables'])) {
            return ['id' => $data['id']];
        }
        ....

And it seems the parent id is used instead of the nested id.
Am I doing something wrong?

image

@soyuka
Copy link
Member

soyuka commented May 28, 2023

Thanks @mdieudonne I'll check we need to unset these variables once used. I'll work on a patch asap

@mdieudonne
Copy link
Author

@soyuka I'd be glad to help and contribute, if you can drive me a bit on what needs to be done :)

@soyuka
Copy link
Member

soyuka commented May 29, 2023

#5604 lmk if that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants