Skip to content

use_symfony_listeners: true with read + input disabled leads to Could not resolve argument $data #8354

Description

@tandev

API Platform version(s) affected: 4.3.14

Description
Using a custom processor like:

input:       false,
read:        false,
processor:   BookProcessor::class,

with use_symfony_listeners: true enabled in api_platform.yaml leads to

{"title":"An error occurred","detail":"Could not resolve argument $data of \"api_platform.action.placeholder::__invoke()\", maybe you forgot to register the controller as a service or missed tagging it with the \"controller.service_arguments\"?","status":500,"type":"\/errors\/500","trace":[{"file":"\/home\/tanders\/code\/other\/apiplatform-fiddling\/vendor\/symfony\/http-kernel\/Controller\/ArgumentResolver\/TraceableValueResolver.php","line":37,"function":"resolve","class":"Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolver\\NotTaggedControllerValueResolver","type":"->"},

A Resource like:
How to reproduce

#[ApiResource(
    operations: [
        new Post(
            uriTemplate: '/books/{id}',
            input:       false,
            read:        false,
            processor:   BookProcessor::class,
        ),
    ]
)]
class Book
{
    public function __construct(
        public string $title,
    ) {
    }
}

Processor:

class BookProcessor implements \ApiPlatform\State\ProcessorInterface
{

    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
    {
        return new Book('foo');
    }
}

config:

api_platform:
    use_symfony_listeners: true

Possible Solution

Additional Context

  • Changelog 3.3.2 states: You can remove the event_listeners_backward_compatibility_layer flag and set use_symfony_listeners instead. The use_symfony_listeners should be true if you use controllers or if you rely on Symfony event listeners. Note that now flags like read can be forced to true if you want to call a Provider even on POST operations. These are the rules we set up on runtime if no value has been set:
    • use_symfony_listeners: false fixes it for us
  • We started to look into setting read: false on the Post-Operation because the the ReadProvider writes debug messages into the log No provider registered for App\Book
        try {
            $data = $this->provider->provide($operation, $uriVariables, $context);
        } catch (ProviderNotFoundException $e) {
            // In case the dev just forgot to implement it
            $this->logger?->debug('No provider registered for {resource_class}', ['resource_class' => $resourceClass]);
            $data = null;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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