Skip to content

[2.4.3] Unused binding "$requestStack" error if a filter class overrides constructor of AbstractFilter #2804

Description

@karser

After updating to v2.4.3 I started getting Unused binding "$requestStack" in service "Extended\From\AbstractFilter\MyFilter" error.

Here is my config:

_defaults:
    autowire: true
    autoconfigure: true
    public: false

Extended\From\AbstractFilter\MyFilter:
    arguments:
        $managerRegistry: '@doctrine'
        $myParam: 'value'
    tags:
        - { name: 'api_platform.filter', id: 'my_filter' }

And the filter pseudocode:

<?php

namespace Extended\From\AbstractFilter;

use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractFilter;
use Doctrine\ORM\QueryBuilder;
use Psr\Log\LoggerInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;

class MyFilter extends AbstractFilter
{
    /** @var string */
    private $myParam;

    public function __construct(ManagerRegistry $managerRegistry, LoggerInterface $logger = null, string $myParam)
    {
        parent::__construct($managerRegistry, null, $logger);
        $this->myParam = $myParam;
    }

    public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
    {
         //handle
    }

    public function getDescription(string $resourceClass): array
    {
        return [];
    }
}

I was able to fix the error by switching off autowire and autoconfigure for the service:

Extended\From\AbstractFilter\MyFilter:
    autowire: false #was added
    autoconfigure: false #was added
    arguments:
        $managerRegistry: '@doctrine'
        $myParam: 'value'
        $logger: '@logger' #was added
    tags:
        - { name: 'api_platform.filter', id: 'my_filter' }

The further research showed me that the problem is in the overridden constructor.
If I remove the constructor then autowiring works with the original service definition.

Looks like this issue was introduced by #2664

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