DDC-752: Postpone Metadata Validation Until After Driver and loadClassMetadata Has Executed #929

Closed
opened 2026-01-22 12:55:50 +01:00 by admin · 9 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 17, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user mridgway:

Right now the metadata drivers throw exceptions if certain metadata is not specified. While this is convenient for letting the user know about errors, it limits the extensibility of the ORM, specifically what you can do in the loadClassMetadata event. It also means that there is duplicated code in each of the driver implementations for validation.

All validation of the metadata should be postponed until after the metadata driver has executed and also after the loadClassMetadata event has been fired. This way all metadata has been loaded before attempting to validate and the user is still warned about errors. This validation should still be ignored when loading from cache.

Example use case:

Currently, setting a @DiscriminatorMap is required when using inheritance mapping. The loadClassMetadata event provides a way to dynamically set discriminator maps from a config or a database without having to extend a metadata driver.

The specific regression in functionality that this references is MappingException::missingDiscriminatorMap being thrown in the metadata drivers.

Originally created by @doctrinebot on GitHub (Aug 17, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user mridgway: Right now the metadata drivers throw exceptions if certain metadata is not specified. While this is convenient for letting the user know about errors, it limits the extensibility of the ORM, specifically what you can do in the loadClassMetadata event. It also means that there is duplicated code in each of the driver implementations for validation. All validation of the metadata should be postponed until after the metadata driver has executed and also after the loadClassMetadata event has been fired. This way all metadata has been loaded before attempting to validate and the user is still warned about errors. This validation should still be ignored when loading from cache. Example use case: Currently, setting a @DiscriminatorMap is required when using inheritance mapping. The loadClassMetadata event provides a way to dynamically set discriminator maps from a config or a database without having to extend a metadata driver. The specific regression in functionality that this references is MappingException::missingDiscriminatorMap being thrown in the metadata drivers.
admin added the Improvement label 2026-01-22 12:55:50 +01:00
admin closed this issue 2026-01-22 12:55:51 +01:00
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

Comment created by mridgway:

Added specific exception that has been causing issues for my use case. (MappingException::missingDiscriminatorMap)

@doctrinebot commented on GitHub (Aug 17, 2010): Comment created by mridgway: Added specific exception that has been causing issues for my use case. (MappingException::missingDiscriminatorMap)
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

Comment created by romanb:

Sounds like a valid issue to me (and a regression).

The metadata drivers should not do this kind of validation. If this validation needs to be done it should happen later either somewhere in ClassMetadata(Info) or the ClassMetadataFactory.

Assigning this issue to Benjamin since I think he added this discriminator map validation in the drivers. I remember we talked about this but I did not properly recognize this issue either.

@doctrinebot commented on GitHub (Aug 17, 2010): Comment created by romanb: Sounds like a valid issue to me (and a regression). The metadata drivers should not do this kind of validation. If this validation needs to be done it should happen later either somewhere in ClassMetadata(Info) or the ClassMetadataFactory. Assigning this issue to Benjamin since I think he added this discriminator map validation in the drivers. I remember we talked about this but I did not properly recognize this issue either.
Author
Owner

@doctrinebot commented on GitHub (Aug 17, 2010):

Comment created by mridgway:

Committed a fix for my use case at 9acfa8b7c3

This moves the discriminatorMap validation to ClassMetadataFactory::_loadMetadata

@doctrinebot commented on GitHub (Aug 17, 2010): Comment created by mridgway: Committed a fix for my use case at http://github.com/mridgway/doctrine2/commit/9acfa8b7c3ea17f4ee75608deb4cb474a799353c This moves the discriminatorMap validation to ClassMetadataFactory::_loadMetadata
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Comment created by @beberlei:

fixed

@doctrinebot commented on GitHub (Aug 27, 2010): Comment created by @beberlei: fixed
Author
Owner

@doctrinebot commented on GitHub (Aug 27, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 27, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Aug 28, 2010):

Comment created by romanb:

I'm not sure but is it right that this validation in the CMF takes place before the loadClassMetadata event is fired? After all, this event is supposed to be used for dynamic completion of the metadata.

@doctrinebot commented on GitHub (Aug 28, 2010): Comment created by romanb: I'm not sure but is it right that this validation in the CMF takes place **before** the loadClassMetadata event is fired? After all, this event is supposed to be used for dynamic completion of the metadata.
Author
Owner

@doctrinebot commented on GitHub (Aug 28, 2010):

Comment created by @beberlei:

i shouldn't code at late in the night, will fix it :)

@doctrinebot commented on GitHub (Aug 28, 2010): Comment created by @beberlei: i shouldn't code at late in the night, will fix it :)
Author
Owner

@doctrinebot commented on GitHub (Aug 28, 2010):

Comment created by @beberlei:

@Roman, what about the ID stuff? Can i just move the event before every CMF validation?

@doctrinebot commented on GitHub (Aug 28, 2010): Comment created by @beberlei: @Roman, what about the ID stuff? Can i just move the event before every CMF validation?
Author
Owner

@doctrinebot commented on GitHub (Aug 28, 2010):

Comment created by romanb:

Maybe, but I would just try to leave the old order intact to not risk any BC issues. Simply moving the inheritance validation below the event should be enough for now.

@doctrinebot commented on GitHub (Aug 28, 2010): Comment created by romanb: Maybe, but I would just try to leave the old order intact to not risk any BC issues. Simply moving the inheritance validation below the event should be enough for now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#929