Closed
Closed
Copy link
Description
Symfony version(s) affected
6.3.1
Description
When I try to serialise a filtered Doctrine array collection:
#[Groups(['profile:get'])]
#[SerializedName('profileMedia')]
public function getPublicProfileMedia(): Collection
{
return $this->profileMedia->filter(static fn ($key, ProfileMedia $media) => $media->getMediaType() === 1);
}
it'll throw me this error:
"hydra:title": "An error occurred",
"hydra:description": "Warning: Undefined array key \"file\"",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/srv/app/vendor/symfony/property-access/PropertyAccessor.php",
"line": 416,
"args": []
},
{
"namespace": "Symfony\\Component\\PropertyAccess",
"short_class": "PropertyAccessor",
"class": "Symfony\\Component\\PropertyAccess\\PropertyAccessor",
"type": "->",
"function": "readProperty",
"file": "/srv/app/vendor/symfony/property-access/PropertyAccessor.php",
"line": 112,
"args": [
[
"array",
[
[
"object",
"App\\Entity\\Profile"
]
]
],
[
"string",
"publicProfileMedia"
],
[
"boolean",
false
]
]
},
{
"namespace": "Symfony\\Component\\PropertyAccess",
"short_class": "PropertyAccessor",
"class": "Symfony\\Component\\PropertyAccess\\PropertyAccessor",
"type": "->",
"function": "getValue",
"file": "/srv/app/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 598,
"args": [
[
"object",
"App\\Entity\\Profile"
],
[
"string",
"publicProfileMedia"
]
]
},
{
"namespace": "ApiPlatform\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "getAttributeValue",
"file": "/srv/app/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 189,
"args": [
[
"object",
"App\\Entity\\Profile"
],
[
"string",
"publicProfileMedia"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"profile:get"
]
]
],
"operation_name": [
"string",
"_api_/profiles/{id}{._format}_get"
],
"operation": [
"object",
"ApiPlatform\\Metadata\\Get"
],
"resource_class": [
"string",
"App\\Entity\\Profile"
],
"skip_null_values": [
"boolean",
true
],
"iri_only": [
"boolean",
false
],
"request_uri": [
"string",
"/api/profiles/01894fb7-21bd-70bf-853e-1d8a263e3357"
],
"uri": [
"string",
"https://localhost/api/profiles/01894fb7-21bd-70bf-853e-1d8a263e3357"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"uri_variables": [
"array",
{
"id": [
"string",
"01894fb7-21bd-70bf-853e-1d8a263e3357"
]
}
],
"exclude_from_cache_key": [
"array",
[
[
"string",
"root_operation"
],
[
"string",
"operation"
],
[
"string",
"resources"
],
[
"string",
"resources_to_push"
]
]
],
"resources": [
"object",
"ApiPlatform\\Serializer\\ResourceList"
],
"resources_to_push": [
"object",
"ApiPlatform\\Serializer\\ResourceList"
],
"debug_trace_id": [
"string",
"64b013c2bd10a"
],
"PROFILE_SELF_NORMALIZER_ALREADY_CALLED": [
"boolean",
true
],
"api_sub_level": [
"boolean",
true
],
"jsonld_has_context": [
"boolean",
true
],
"iri": [
"string",
"/api/profiles/01894fb7-21bd-70bf-853e-1d8a263e3357"
],
"api_normalize": [
"boolean",
true
],
"cache_key": [
"string",
"6af1ccd1143f38a0ae3c827065ceee64"
],
"circular_reference_limit_counters": [
"array",
{
"00000000000025d30000000000000000": [
"integer",
1
]
}
],
"api_attribute": [
"string",
"publicProfileMedia"
]
}
]
]
},
...
Serialising the unfiltered collection works.
How to reproduce
Try serialise a filtered doctrine collection.
Possible Solution
No response
Additional Context
No response