[Object Mapper] IriFilter / IriConverterParameterProvider fails to find items when filtering mapped resources
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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! 🙌
- Ngôn ngữ chính
- PHP
- Star
- 2.6k
- Fork
- 988
- Merge trung bình
- 4 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 92
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/core
-
API Platform ignores array shapes in the JSON SchemaCó thể đã có người làm @afraca đã nhận 9 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
api-platform/core#8766 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
api-platform/core#8744 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 80/100
api-platform/core#8701 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
api-platform/core#8791 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Preserve exact SearchFilter behaviour for Doctrine collection associations with QueryParameterĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
api-platform/core#8790 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của api-platform/core
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Automattic/blocks-engine#4355 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
opcache: smm_shared_globals left pointing to a dead stack frame when there is no SHM backendĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
agentic bug complete-verify
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
MagnaCapax/PMSS#1234 ·
Maintainer thường phản hồi trong vòng 3 ngày