[Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata - #65647
#65647[Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata#65647nicolas-grekas merged 1 commit intosymfony:6.4symfony/symfony:6.4from oliinykdm:fix/serializer-max-depth-proxyoliinykdm/symfony:fix/serializer-max-depth-proxyCopy head branch name to clipboard
Conversation
|
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
d3f3097 to
1431a01
Compare
1431a01 to
3a040d0
Compare
nicolas-grekas
left a comment
There was a problem hiding this comment.
Thank you @oliinykdm.
Root cause confirmed: ClassMetadataFactory merges the parent class metadata into the subclass, so a proxy inherits MaxDepth(1), but the depth counter key is built from the runtime class, so the proxy gets its own counter. The new test fails on the 6.4 tip with the extra linked level and passes with the fix.
I rebased on 6.4 and dropped the two @return mixed docblock removals, which are unrelated to this fix.
About the red jobs: the Windows job fails in AmpHttpClientTest::testNonBlockingStream, and the high-deps job fails in Serializer denormalization tests (testRejectInvalidKey, testCollectDenormalizationErrors) on the key-type check of nestedObject[int]. That is a denormalization path this PR does not touch; it comes from a dependency drift since the last 6.4 branch run on August 4.
|
Thank you @oliinykdm. |
|
@nicolas-grekas Thank you! Happy that it was helpful! |
MaxDepthis counted per runtime class name. A Doctrine proxy is a subclass of the entity, so it gets its own counter. Withmax_depth: 1, a graph of entity → proxy → entity is serialized two levels deep instead of one.The depth key now uses the parent class when that parent declares the same
MaxDepthvalue. A proxy and its entity then share one counter.