-
-
Notifications
You must be signed in to change notification settings - Fork 933
Open
Description
API Platform version(s) affected: 4.2.0
Description
When writing a route on the User class with a custom input like
new Patch(
uriTemplate: '/users/{uuid}/verify',
input: UserVerifyInput::class,
processor: UserProcessor::class,
),
with an input like
class UserVerifyInput { public string $code; }
In the UserProcessor::process method,
-
If I use
use_symfony_listeners: true
- the context has a previous_data which is the clone of the user resource but does not have a reference to the real user resource allowing to modify it.
request->attributes->get('data')
returns the UserVerifyInput
-
If I use
use_symfony_listeners: false
- the context has a previous_data AND a data key. The second one is the right reference to the real user resource.
request->attributes->get('data')
returns the User reference
I assume it's because of the DeserializeListener which override the data attribute AND the WriteListener which doesn't add a data key to the context.
On the opposite, the MainController does
$body = $this->provider->provide($operation, $uriVariables, $context);
$context['previous_data'] = $request->attributes->get('previous_data');
$context['data'] = $request->attributes->get('data');
How to reproduce
Already given
Possible Solution
It would require
- To expose
data
here'previous_data' => false === $operation->canRead() ? null : $request->attributes->get('previous_data'),
'data' => false === $operation->canRead() ? null : $request->attributes->get('data'),
- To not override the data attribute here
$request->attributes->set('data', $data);
$request->attributes->set('deserialized_data', $data);
But when I try, I get an error in
final class PlaceholderAction |
Could not resolve argument $data of \u0022api_platform.action.placeholder::__invoke()
So I think it would also to rewrite this placeholder action to something like
public function __invoke(Request $request)
{
return $request->attributes->get('deserialized_data')
?? $request->attributes->get('data');
}
WDYT @soyuka ?
Metadata
Metadata
Assignees
Labels
No labels