[PR #10557] Fix regression with an edge case for the CMF::peekIfIsMappedSuperclass() method #12455

Closed
opened 2026-01-22 16:14:06 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/10557

State: closed
Merged: No


This comment hints to a case where the ClassMetadataFactory::peekIfIsMappedSuperclass() method introduced in #10411 causes a failure.

CMF::peekIfIsMappedSuperclass() has to perform improvised metadata loading in a situation where the CMF is currently loading a class. So, we cannot use the full/real ClassMetadataFactory mechanisms, since it would require a re-entry for a subclass of the current class, causing an infinite loop (loads parent classes first, and that's what we're currently doing).

The problem is that the improvised call to $driver->loadMetadataForClass() cannot provide a pre-filled ClassMetadata instance populated with all parent class fields and associations. But, when attribute or association overrides are used, a check is made to see if the overridden field/association actually exists, and this information is missing in that situation.

This PR suggests to override the methods to get around this. In fact, we do not care about all these details, we only want to ask the driver if the class is a mapped superclass or not.

A much better fix would be to have a dedicated method on the driver to ask it just that particular question (also better performance-wise). But I do not see how we could get that done in a BC way – ideas? 💡

A few things that need to come together to make the bug surface:

  • Load an entity declaring an inheritance tree
  • There must be a mapped superclass in the inheritance tree to provide the field that shall be overriden
  • An entity class must inherit from the mapped superclass and override the field
  • That entity class must be an abstract, intermediate class not be declared in the discriminator map so we can "discover" it
  • The overriden property must be private so the mapping drivers (using reflection) do not see it when looking at the overriding entity class.
**Original Pull Request:** https://github.com/doctrine/orm/pull/10557 **State:** closed **Merged:** No --- [This comment](https://github.com/doctrine/orm/pull/10473#issuecomment-1450048660) hints to a case where the `ClassMetadataFactory::peekIfIsMappedSuperclass()` method introduced in #10411 causes a failure. `CMF::peekIfIsMappedSuperclass()` has to perform improvised metadata loading in a situation where the CMF is currently loading a class. So, we cannot use the full/real `ClassMetadataFactory` mechanisms, since it would require a re-entry for a subclass of the current class, causing an infinite loop (loads parent classes first, and that's what we're currently doing). The problem is that the improvised call to `$driver->loadMetadataForClass()` cannot provide a pre-filled `ClassMetadata` instance populated with all parent class fields and associations. But, when attribute or association overrides are used, a check is made to see if the overridden field/association actually exists, and this information is missing in that situation. This PR suggests to override the methods to get around this. In fact, we do not care about all these details, we only want to ask the driver if the class is a mapped superclass or not. A much better fix would be to have a dedicated method on the driver to ask it just that particular question (also better performance-wise). But I do not see how we could get that done in a BC way – ideas? 💡 A few things that need to come together to make the bug surface: * Load an entity declaring an inheritance tree * There must be a mapped superclass in the inheritance tree to provide the field that shall be overriden * An entity class must inherit from the mapped superclass and override the field * That entity class must be an abstract, intermediate class not be declared in the discriminator map so we can "discover" it * The overriden property must be private so the mapping drivers (using reflection) do not see it when looking at the overriding entity class.
admin added the pull-request label 2026-01-22 16:14:06 +01:00
admin closed this issue 2026-01-22 16:14:06 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#12455