Skip to content

[Serializer][PropertyInfo] PHPDocExtractor is failing with array<string, mixed> #47224

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
Hanmac opened this issue Aug 8, 2022 · 6 comments
Closed

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Aug 8, 2022

Symfony version(s) affected

4.4.x

Description

I was first using a Mockup UnitTest using ReflectionExtractor with ObjectNormalizer which did work

then i was trying to use a functional Test where i wanted to have the Services, but the Denormalize is failing:

The type of the "settings" attribute for class "Sonata\PageBundle\Tests\App\Entity\SonataPageBlock" must be one of "rray<string,mixed>"

This is the property:

    /**
     * @var array<string, mixed>
     */
    protected $settings;

notice the missing a from array?

i assume that this version of PropertyInfo the PHPDoc Extractor has problems with such array type, or is the definition wrong?

How to reproduce

Class Block
{

    /**
     * @var array<string, mixed>
     */
    protected $settings;


    public function setSettings(array $settings = []): void
    {
        $this->settings = $settings;
    }

    public function getSettings(): array
    {
        return $this->settings;
    }
}

Did a Breakpoint in the constructor of PropertyInfoExtractor
The $typeExtractors is called with a generator with 2 closures, the first is the doctrine Extractor, the second is the phpdoc extractor, the third one is missing, the count of the generator is 3

and the PHPDoc Extractor does something stupid with the type

Possible Solution

No response

Additional Context

Error when trying to denormalize

Symfony\Component\Serializer\Exception\NotNormalizableValueException : The type of the "settings" attribute for class "Sonata\PageBundle\Tests\App\Entity\SonataPageBlock" must be one of "rray<string,mixed>" ("array" given).
 /opt/project/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:477
 /opt/project/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:358
 /opt/project/vendor/symfony/serializer/Serializer.php:191
@Hanmac Hanmac added the Bug label Aug 8, 2022
@Hanmac Hanmac changed the title [Serializer][Property-Info] Failed to load ReflectionExtractor and PHPDocExtractor is failing with array<string, mixed> [Serializer][PropertyInfo] Failed to load ReflectionExtractor and PHPDocExtractor is failing with array<string, mixed> Aug 8, 2022
@xabbuh
Copy link
Member

xabbuh commented Aug 9, 2022

Can you create a small example application that allows to reproduce your issue?

@Hanmac
Copy link
Contributor Author

Hanmac commented Aug 9, 2022

i will see if i can get the right conditions to repoduce it in a smaller setting
See the Linked MR for a test case.
I was using composer update --prefer-lowest

what i can say for now:

  • The "rray<string,mixed>" to "array<string,mixed>" in the error got fixed somewhere between 4.4.36 and 4.4.40 of the property-info, but it still makes this error.
  • The whole testcase got fixed after using property-info 5.4.* while still using 4.4.* for the other symfony packages

For the ReflectionExtractor i probably need to debug more if i need 5.4.* for it to be added to the PropertyInfoExtractor

@Hanmac
Copy link
Contributor Author

Hanmac commented Aug 11, 2022

@xabbuh i found the reason for my problem:
symfony/property-info@df0299f#diff-f5da9aa3f4405371613f781be42e834db50b5854b01274130f83a28a80fc3acb

This Fix right there isn't part of the 4.4.* branch for property-info

for the ReflectionExtractor thing, i missunderstood the generators iterable wrong, it was there, just the faulty phpdoc extractor took preference over it

@Hanmac Hanmac changed the title [Serializer][PropertyInfo] Failed to load ReflectionExtractor and PHPDocExtractor is failing with array<string, mixed> [Serializer][PropertyInfo] PHPDocExtractor is failing with array<string, mixed> Aug 18, 2022
@Hanmac
Copy link
Contributor Author

Hanmac commented Aug 18, 2022

@xabbuh how do i request such changes be backported to 4.4.* ?

@MatTheCat
Copy link
Contributor

#37559 was first targeted to 4.4 but

We would consider this as a new feature indeed.

so I don’t think it will change. You can check the PR comments though as some are workarounds.

@xabbuh
Copy link
Member

xabbuh commented Aug 24, 2022

@MatTheCat is right. We do not backport features to already released branches. Updating to 5.4 or trying one of the described workarounds is indeed the solution.

@xabbuh xabbuh closed this as completed Aug 24, 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

4 participants