8000 [Serializer] Setting COLLECT_DENORMALIZATION_ERRORS in default_context of framework config has no effect · Issue #58628 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Setting COLLECT_DENORMALIZATION_ERRORS in default_context of framework config has no effect #58628

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
freddytqg opened this issue Oct 22, 2024 · 2 comments · Fixed by #58889

Comments

@freddytqg
Copy link
freddytqg commented Oct 22, 2024

Symfony version(s) affected

7.1.*

Description

Adding COLLECT_DENORMALIZATION_ERRORS to the framework.default_context has no effect if you want to collect denormalization errors for all ->denormalize calls. It only works, if it is added to each ->denormalize call as an extra argument.

How to reproduce

Framework Config

# config/packages/framework.yaml
framework:
    # ...
    serializer:
        default_context:
            !php/const Symfony\Component\Serializer\Normalizer\DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS: true

Object

final readonly class Foo
{
    public function __construct(
        public string $bar,
    ) {}
}

Denormalize call:

public function __construct(
        private DenormalizerInterface $denormalizer,
    ) {
    }

    public function __invoke(): void
    {
        $this->denormalizer->denormalize(
            data: [],
            type: Foo::class,
        );
    }

Expected: \Symfony\Component\Serializer\Exception\PartialDenormalizationException is thrown
Actual: \Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException is thrown

Possible Solution

If this is intended behaviour, I would suggest to add this to the documentation here, that it cannot be set as a default.

If this is not an intended behaviour, maybe there is a way to get the context of the used $normalizer at this line in the Serializer Class and use it as another check if it is not set in $context.

Additional Context

No response

@mtarld
Copy link
Contributor
mtarld commented Oct 25, 2024

Hey @freddytqg, thanks for the issue!

Indeed, this is not an intended behavior, would you like to create a bug fix PR targeting 6.4? 🙂

@freddytqg
Copy link
Author

@mtarld sorry for the late reply. Unfortunately, I am pretty busy at the moment, so don't expect a PR in the near future. If anyone else has an idea and time to solve it, feel free :)

chalasr added a commit that referenced this issue Jan 28, 2025
This PR was merged into the 6.4 branch.

Discussion
----------

[Serializer] Handle default context in Serializer

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  |  no
| Deprecations? | no
| Issues        | Fix #58628
| License       | MIT

This fixes the default context not taken into account by the Serializer class.

Commits
-------

4400674 [Serializer] fix default context in Serializer
@chalasr chalasr closed this as completed Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0