Skip to content

[PropertyAccess] Class property ignored when unrelated methods are marked as ignored instead #45016

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
Jeroeny opened this issue Jan 13, 2022 · 1 comment

Comments

@Jeroeny
Copy link
Contributor

Jeroeny commented Jan 13, 2022

Symfony version(s) affected

6.*

Haven't checked any older versions.

Description

Given I have a class like:

abstract class Bad
{
    #[Ignore]
    private bool $create = false;

    #[Ignore]
    private bool $delete = false;

    private Uuid $id;

    public function __construct(Uuid $id)
    {
        $this->id = $id;
    }

...
$this->serializer->serialize(new BadOne(Uuid::v4()),'json'); 
// returns: {"foo":"foo"}
// expected: {"foo":"foo","id":"597eb634-7aff-4513-ba1c-c928e01ff60c"}

Now when a child class is (de)serialized, the id property is marked as ignored and not included in the output. The linked reproducer should give some more details.

This could be a fairly critical bug in some cases, because if the serializer is user for DB entities, values can be lost.

How to reproduce

https://github.com/Jeroeny/reproduce/tree/annotate

Possible Solution

No response

Additional Context

No response

@astepin
Copy link
Contributor

astepin commented Jul 14, 2022

Hey @Jeroeny ive created a fix for that here: #46947
Thanks for your example in your repo. That helped me a lot.

astepin added a commit to CloudPlayDev/symfony that referenced this issue Jul 15, 2022
astepin added a commit to CloudPlayDev/symfony that referenced this issue Jul 15, 2022
astepin added a commit to CloudPlayDev/symfony that referenced this issue Jul 15, 2022
chalasr added a commit that referenced this issue Jul 15, 2022
…ad to incorrect results (astepin)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Prevent that bad Ignore method annotations lead to incorrect results

fix #45016

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

By attaching the Ignore serializer annotation to a method that is not a set/get/has/is method, the property that was read before the method was marked as ignored.
I have tweaked the behavior here so that it matches the other annotations.

However, the change could now cause exceptions in older projects if they already have this bug built in.
From my point of view, however, this is justifiable, because at the moment data may not be output correctly.

Commits
-------

edb1038 Prevent that bad Ignore method annotations lead to incorrect results
@chalasr chalasr closed this as completed Jul 15, 2022
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

5 participants