Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

[Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata - #65647

#65647
Merged
nicolas-grekas merged 1 commit into
symfony:6.4symfony/symfony:6.4from
oliinykdm:fix/serializer-max-depth-proxyoliinykdm/symfony:fix/serializer-max-depth-proxyCopy head branch name to clipboard
Aug 26, 2026
Merged

[Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata#65647
nicolas-grekas merged 1 commit into
symfony:6.4symfony/symfony:6.4from
oliinykdm:fix/serializer-max-depth-proxyoliinykdm/symfony:fix/serializer-max-depth-proxyCopy head branch name to clipboard

Conversation

@oliinykdm

Copy link
Copy Markdown
Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58526
License MIT

MaxDepth is counted per runtime class name. A Doctrine proxy is a subclass of the entity, so it gets its own counter. With max_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 MaxDepth value. A proxy and its entity then share one counter.

$a = new Dossier();
$b = new DossierProxy(); // subclass, same MaxDepth metadata
$c = new Dossier();
$a->linkedDossiers = $b;
$b->linkedDossiers = $c;

$normalizer->normalize($a, null, ['enable_max_depth' => true]);
// before: A → B → C
// after:  A → B

@carsonbot

Copy link
Copy Markdown

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:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 8.2 branch.

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!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title fix: fix max depth counting for subclasses that inherit MaxDepth metadata fix: fix max depth counting for subclasses that inherit MaxDepth metadata Aug 25, 2026
@oliinykdm oliinykdm changed the title fix: fix max depth counting for subclasses that inherit MaxDepth metadata [Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata Aug 25, 2026
@oliinykdm
oliinykdm force-pushed the fix/serializer-max-depth-proxy branch from d3f3097 to 1431a01 Compare August 25, 2026 21:44

@nicolas-grekas nicolas-grekas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@carsonbot carsonbot changed the title [Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata Fix max depth counting for subclasses that inherit MaxDepth metadata Aug 26, 2026
@carsonbot carsonbot changed the title Fix max depth counting for subclasses that inherit MaxDepth metadata [Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata Aug 26, 2026
@nicolas-grekas

Copy link
Copy Markdown
Member

Thank you @oliinykdm.

@nicolas-grekas
nicolas-grekas merged commit 1b0bfd1 into symfony:6.4 Aug 26, 2026
12 of 14 checks passed
@oliinykdm

Copy link
Copy Markdown
Author

@nicolas-grekas Thank you! Happy that it was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.