Skip to content

[PropertyAccessor] Error when trying to serialise filtered doctrine array collection #50967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KDederichs opened this issue Jul 13, 2023 · 1 comment

Comments

@KDederichs
Copy link
Contributor

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

@KDederichs KDederichs added the Bug label Jul 13, 2023
nicolas-grekas added a commit that referenced this issue Jul 13, 2023
…hecking stack frames (nicolas-grekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[PropertyAccess] Fix access to undefined "file" key when checking stack frames

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #50967
| License       | MIT
| Doc PR        | -

Commits
-------

ce75444 [PropertyAccess] Fix access to undefined "file" key when checking stack frames
@nicolas-grekas
Copy link
Member

Should be fixed by #50968, thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants