Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot PATCH/PUT the resource which contains fields with IRI values #5603

@jelovac

Description

@jelovac

API Platform version(s) affected: 3.1.12

Description

Upgraded API Platform from 3.1.9 to 3.1.12.

The issue I am experiencing is that when doing PATCH/PUT request and providing in that request a field which is a relation with IRI value, the value does not get resolved properly.

Basically what happens is the following:

  1. Item provider loads for the PATCH/PUT request the resource I am trying to update
  2. Next it calls again the Item Provider for all the fields with IRI value in the PATCH payload
  3. This happens here: vendor/api-platform/core/src/Symfony/Routing/IriConverter.php:95
        if ($item = $this->provider->provide($operation, $uriVariables, $context)) {
            return $item;
        }

        throw new ItemNotFoundException(sprintf('Item not found for "%s".', $iri));
  1. The problem is that it doesn't pass the correct ID, instead of the embedded resource ID the ID which is passed to the provider is the initial id of the PUT object, so the above code will always throw an exception.

How to reproduce

  1. Create two resources, for example Alpha and Beta
  2. Create a field in Beta which is a relation to Alpha
  3. Try to create/update Beta
PATCH /betas/{id}
{
  "alpha": "/alphas/{id}"
}

It will throw 400 error. And it basically throws ItemNotFoundException due to wrong identifier being passed to state provider.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions