-
-
Notifications
You must be signed in to change notification settings - Fork 895
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
v3.3.8: Embedded subresources no longer denormalizing #6465
Comments
when denormalizing a relation the context should be reset ($context should not point to Tax) can you give me your configuration? |
I have the same issue with 3.3.8. Operation: new Post(
uriTemplate: '/venues/{id}/validate-settings',
uriVariables: ['id' => new Link(fromClass: Venue::class)],
status: 200,
input: ValidateVenueSettingsInput::class,
output: VenueSettingsValidationOutput::class,
processor: VenueSettingsValidatorProvider::class,
), Input DTO: class ValidateVenueSettingsInput
{
#[Assert\NotBlank]
public EmailType $template; // enum
#[Assert\NotBlank]
public Language $language; // doctrine entity and API resource
} The error I got: 'Invalid IRI "/api/languages/018f15ed-e7d1-7c98-a407-3de1522dcd63".'. It was caused precisely by the abovementioned code from paullallier. |
If there's the provider I need a provider to reproduce, can anyone create a minimal repro? Also what's your |
During debugging, the code didn't even reach the processor (I have a typo in the class name; it's not the provider). The error occurred during deserializing the input DTO class. Standard put is set to true. But the operation is |
What's your |
Here is the example repo: https://github.com/fvozar/input-dto-bug/tree/main There are two entities Foo and Bar. I've created one Foo and two Bar objects. Then I called endpoint {
"bar": "/api/bars/2"
} The IRI with different value for ID is important here, because when I use Response: {
"@id": "/api/errors/400",
"@type": "hydra:Error",
"title": "An error occurred",
"detail": "Invalid IRI \"/api/bars/2\".",
"status": 400,
"type": "/errors/400",
"trace": [],
"hydra:title": "An error occurred",
"hydra:description": "Invalid IRI \"/api/bars/2\"."
} Full curl: curl -X 'POST' \
'https://127.0.0.1:8001/api/foo/1/validate' \
-H 'accept: application/ld+json' \
-H 'Content-Type: application/ld+json' \
-d '{
"bar": "/api/bars/2"
}' I haven't changed anything special in config, it's new project with Api platform installed. For real-world example in my application I'm using {"template":"reservationContractCreated","language":"/api/languages/018f15ed-e7d1-7c98-a407-3de1522dcd63"} |
nice thanks, I'll check that out! |
Thanks guys |
can you check my patch (install a dev version of 3.3) and let me know, I'll tag a release shortly if it's alright |
No - I've patched 3.3.7 which wasn't broken. I'll run it again. |
Hello @soyuka, I can confirm that your patch works in my case. Thanks a lot 👍 |
If I explicitly define I suspect I might not be the only person this changes catches out though... |
@paullallier can you please give me a stack trace? it must be a similar issue where |
I'm guessing: diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php
index 0042511fe..ede5ebfcb 100644
--- a/src/Serializer/AbstractItemNormalizer.php
+++ b/src/Serializer/AbstractItemNormalizer.php
@@ -761,6 +761,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
unset(
$context['resource_class'],
$context['force_resource_class'],
+ $context['uri_variables'],
);
// Anonymous resources
@@ -791,8 +792,11 @@ protected function getAttributeValue(object $object, string $attribute, ?string
throw new LogicException(sprintf('The injected serializer must be an instance of "%s".', NormalizerInterface::class));
}
- unset($context['resource_class']);
- unset($context['force_resource_class']);
+ unset(
+ $context['resource_class'],
+ $context['force_resource_class'],
+ $context['uri_variables']
+ );
$attributeValue = $this->propertyAccessor->getValue($object, $attribute);
|
It looks like declaring the input class explicitly does fix things (it's still failing for me in a few tests, but I suspect they are other places that also need the input class defined). If we don't want to force people to define the input class (which I suspect we is undesirable to require), your patch to getAttributeValue() doesn't help me. This is the stack trace were it's failing for me:
|
thanks, updated my patch accordingly see https://github.com/api-platform/core/pull/6469/files |
released |
API Platform version(s) affected: 3.3.8 (works in 3.3.7)
Description
![Screenshot 2024-07-12 at 13 06 18](https://private-user-images.githubusercontent.com/42591123/348255578-dc7a4f93-60ba-4b7f-b3c9-bb903a0ba3e5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMDEwMTksIm5iZiI6MTczOTEwMDcxOSwicGF0aCI6Ii80MjU5MTEyMy8zNDgyNTU1NzgtZGM3YTRmOTMtNjBiYS00YjdmLWIzYzktYmI5MDNhMGJhM2U1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDExMzE1OVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjZmYzNTM5MzYzYjk5ZGY2NmIxOGU4MjJjMDM5ZDFkNTgwMjNkMjFjMTkyN2YyYWY1NzlkYWY3OTgzZWQxNzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.gdaYGYskFR6161ZO3oIklPnbUCY78a5ML67J5uHkZSE)
I've got a PUT endpoint like this:
I'm having trouble with the embedded /accounts/{id} IRI in 3.3.8, which I think relates to the changes to IriConverter in #6451.
In 3.3.7, it pulls the account entity from the database fine. In 3.3.8, it fails on this check, which was added in that PR, I think.
https://github.com/ili101/api-platform-core/blob/14cc145ce646fe4a799652f5b451d0140076cf18/src/Symfony/Routing/IriConverter.php#L81
At that point, my $context points to the Tax entity, but it would still find the GET operation for the Account entity in 3.3.7. Now it complains that I have an IRI for the wrong type of resource instead.
I suspect this might be an edge case that the tests are missing? (Or I'm using API-P in an unusual way again...)
The text was updated successfully, but these errors were encountered: