-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Serializer] Fixing PHP warning in the ObjectNormalizer with MaxDepth enabled #54395
Conversation
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate a bit on how your fix works? I don't understand it. 😓
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
What happens if To me, the right fix would be handle properly the case where there is no |
Regarding the test failure, I'm not sure why that Redis test is failing now, perhaps something in the dependencies updated? I removed my fix and ran just that test, fails with or without my fix in place, so don't believe it's a result of the change to this PR. |
Status: Needs Review |
@@ -703,7 +703,7 @@ private function updateData(array $data, string $attribute, mixed $attributeValu | |||
private function isMaxDepthReached(array $attributesMetadata, string $class, string $attribute, array &$context): bool | |||
{ | |||
if (!($enableMaxDepth = $context[self::ENABLE_MAX_DEPTH] ?? $this->defaultContext[self::ENABLE_MAX_DEPTH] ?? false) | |||
|| null === $maxDepth = $attributesMetadata[$attribute]?->getMaxDepth() | |||
|| !isset($attributesMetadata[$attribute]) || null === $maxDepth = $attributesMetadata[$attribute]?->getMaxDepth() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be:
|| !isset($attributesMetadata[$attribute]) || null === $maxDepth = $attributesMetadata[$attribute]?->getMaxDepth() | |
|| null === $maxDepth = ($attributesMetadata[$attribute]?->getMaxDepth() ?? null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning is still thrown in that case as $attributesMetadata[$attribute]
is still trying to be accessed.
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
@jaydiablo This PR must be rebased to get rid of the merge commits. |
@fabpot rebased |
74a7849
to
31e3bde
Compare
Thank you @jaydiablo. |
This fixes a specific issue I ran into when testing an application in Symfony 6 that uses the rompetompe/inertia-bundle to serialize PHP data to JSON for use by Inertia.js.
Added a test that is as minimal as necessary for the Warning to be thrown. I tested against Symfony 5.4 as well, but the issue doesn't seem to be present there (could have something to do with 5.4 not having the AttributeLoader).