[Object Mapper] IriFilter / IriConverterParameterProvider fails to find items when filtering mapped resources
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- api, backend-api-design
Direzione di ricerca
Start by reading Doctrine ORM's IriFilter and IriConverterParameterProvider, then trace how the bar query parameter is handled for the mapped FooResource relation relation.bar. The report says filtering should match the underlying entity relation for /v2/foos?bar=/v2/bars/2; verify whether the mapped resource value causes the mismatch and identify the relevant test coverage.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- API Platform version:
v5.0.5 - Symfony version:
8.1.*(symfony/object-mapper) - PHP version:
8.5 - Doctrine ORM:
^3.6.8
Description
Hey everyone!
I've been testing API Platform's new Object Mapper feature (Symfony\Component\ObjectMapper\Attribute\Map) with custom DTO resources acting as Entity DTOs, and it's honestly amazing. Everything works super smoothly—except when trying to filter a collection using an IriFilter combined with an IriConverterParameterProvider on a mapped relation (especially with nested property paths).
When calling an endpoint with an IRI filter like ?bar=/v2/bars/2, Doctrine successfully finds the target resource, but the filter ends up evaluating to false or failing to match because the IriFilter receives the already-mapped resource instead of resolving it against the underlying entity relation.
In the example below, when calling /v2/bars/2
the $value is an instance of BarResource.
Code Snippets
1. Collection Resource (FooResource)
namespace App\ApiResource\V2\Foo;
use ApiPlatform\Doctrine\Orm\Filter\IriFilter;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\QueryParameter;
use ApiPlatform\State\ParameterProvider\IriConverterParameterProvider;
use App\ApiResource\V2\Bar\BarResource;
use App\Entity\FooEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[ApiResource(
uriTemplate: '/v2/foos',
operations: [
new GetCollection(
parameters: [
'bar' => new QueryParameter(
provider: IriConverterParameterProvider::class,
filter: new IriFilter(),
property: 'relation.bar',
)
],
itemUriTemplate: FooResource::uriTemplate,
),
],
stateOptions: new Options(entityClass: FooEntity::class)
)]
#[Map(source: FooEntity::class)]
class FooResource
{
public const string uriTemplate = '/v2/foos/{id}';
#[ApiProperty(identifier: true)]
public int $id;
public ?float $amount = null;
#[Map(source: 'relation.bar.name')]
public string $barName;
#[Map(source: 'relation.bar')]
public BarResource $bar;
// ... other mappings
}
2. Related Resource (BarResource)
namespace App\ApiResource\V2\Bar;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use App\Entity\BarEntity;
use Symfony\Component\ObjectMapper\Attribute\Map;
#[ApiResource(
operations: [
new Get(
uriTemplate: self::uriTemplate
)
],
stateOptions: new Options(entityClass: BarEntity::class)
)]
#[Map(source: BarEntity::class)]
class BarResource
{
public const string uriTemplate = '/v2/bars/{id}';
#[ApiProperty(identifier: true)]
public int $id;
public string $name;
}
What happens?
- Request:
GET /v2/foos?bar=/v2/bars/2 - The
IriConverterParameterProviderorIriFilterexpects a Doctrine entity to build the database query, but since the resource is mapped via Object Mapper, it gets confused by the IRI / mapped resource representation. - The SQL query ends up generating a clause like:
WHERE f0_.bar_id = ?
where the parameter value evaluates to false or fails to link to entity ID 2.
Interestingly, exact filters on simple IDs work fine, and IRI filters on standard non-mapped entity-backed resources work smoothly too. It specifically comes up when combining Object Mapper with IRI-based query parameters.
Any thoughts on whether this is expected limitation right now, or if there's a recommended workaround / bridge we should use? Thanks a lot! 🙌
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 988
- Merge medio
- 4g 10h
- PR unite (30g)
- 92
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/core
-
API Platform ignores array shapes in the JSON SchemaForse già presa @afraca l’ha presa 9 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
api-platform/core#8766 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
api-platform/core#8744 ·
I maintainer di solito rispondono entro 2 giorni
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 80/100
api-platform/core#8701 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
api-platform/core#8791 ·
I maintainer di solito rispondono entro 2 giorni
-
Preserve exact SearchFilter behaviour for Doctrine collection associations with QueryParameterAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
api-platform/core#8790 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di api-platform/core
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
Automattic/blocks-engine#4355 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
agentic bug complete-verify
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
MagnaCapax/PMSS#1234 ·
I maintainer di solito rispondono entro 3 giorni
-
bug report
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
yiisoft/yii2-docker#193 ·