Allow FQCN in value attribute of discriminator-mapping field #7367

Closed
opened 2026-01-22 15:50:45 +01:00 by admin · 1 comment
Owner

Originally created by @MatteoFeltrin on GitHub (May 13, 2024).

Bug Report

We are storing to database FQCN to later use them to know which class the Entity has to be casted to through a Discriminator map.
We found out the problem updating to newer version of Doctrine which changed the default value of $isXsdValidationEnabled to true.
Actually, the attribute value of discriminator-mapping is set as XS:NMTOKEN in the XSD schema

image

Our XML Configuration of the entity:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="App\Core\EntityVersioning\Domain\Model\EntityVersion" table="entity_version" inheritance-type="SINGLE_TABLE">
    <discriminator-column name="entityType" type="string"/>
    <discriminator-map>
      <discriminator-mapping value="App\Core\Part\Domain\Model\Part" class="App\Core\Part\Domain\Model\PartVersion" />
      <discriminator-mapping value="App\Core\Card\Domain\Model\Card" class="App\Core\Card\Domain\Model\CardVersion" />
    </discriminator-map>
    <field name="version" type="string" nullable="false"/>
    <id name="entityId" type="string"/>
    <id name="entityType" association-key="true"/>
  </entity>
</doctrine-mapping>

Found out this related issue:
https://github.com/doctrine/orm/issues/10627

Q A
BC Break no
Version 3.1.x

Summary

Allow FQCN in value attribute of discriminator-mapping (or just loosen the type validation)

Current behavior

An exception is thrown when the XML is validated against the XSD configuration.

        Doctrine\ORM\Mapping\MappingException: libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Part\Domain\Model\Part' is not a valid value of the atomic type 'xs:NMTOKEN'.
        in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 6
        libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Card\Domain\Model\Card' is not a valid value of the atomic type 'xs:NMTOKEN'.
        in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 7

How to reproduce

Just write a backslash, or FQCN, inside the attribute "value" of a discriminator mapping field and let it be validated against XSD schema

Expected behavior

No exception to be thrown

Originally created by @MatteoFeltrin on GitHub (May 13, 2024). ### Bug Report We are storing to database FQCN to later use them to know which class the Entity has to be casted to through a Discriminator map. We found out the problem updating to newer version of Doctrine which changed the default value of `$isXsdValidationEnabled` to true. Actually, the attribute `value` of `discriminator-mapping` is set as XS:NMTOKEN in the XSD schema ![image](https://github.com/doctrine/orm/assets/119850913/483f232f-d643-4f6f-8ad4-5f83c538eed3) Our XML Configuration of the entity: ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="App\Core\EntityVersioning\Domain\Model\EntityVersion" table="entity_version" inheritance-type="SINGLE_TABLE"> <discriminator-column name="entityType" type="string"/> <discriminator-map> <discriminator-mapping value="App\Core\Part\Domain\Model\Part" class="App\Core\Part\Domain\Model\PartVersion" /> <discriminator-mapping value="App\Core\Card\Domain\Model\Card" class="App\Core\Card\Domain\Model\CardVersion" /> </discriminator-map> <field name="version" type="string" nullable="false"/> <id name="entityId" type="string"/> <id name="entityType" association-key="true"/> </entity> </doctrine-mapping> ``` Found out this related issue: https://github.com/doctrine/orm/issues/10627 | Q | A |------------ | ------ | BC Break | no | Version | 3.1.x #### Summary Allow FQCN in value attribute of discriminator-mapping (or just loosen the type validation) #### Current behavior An exception is thrown when the XML is validated against the XSD configuration. ``` Doctrine\ORM\Mapping\MappingException: libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Part\Domain\Model\Part' is not a valid value of the atomic type 'xs:NMTOKEN'. in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 6 libxml error: Element '{http://doctrine-project.org/schemas/orm/doctrine-mapping}discriminator-mapping', attribute 'value': 'App\Core\Card\Domain\Model\Card' is not a valid value of the atomic type 'xs:NMTOKEN'. in /src/Common/Infrastructure/Persistence/Doctrine/XmlMetadata/App.Core.EntityVersioning.Domain.Model.EntityVersion.dcm.xml at line 7 ``` #### How to reproduce Just write a backslash, or FQCN, inside the attribute "value" of a discriminator mapping field and let it be validated against XSD schema #### Expected behavior No exception to be thrown
admin closed this issue 2026-01-22 15:50:45 +01:00
Author
Owner

@MatteoFeltrin commented on GitHub (Oct 16, 2024):

fixed by https://github.com/doctrine/orm/pull/11453

@MatteoFeltrin commented on GitHub (Oct 16, 2024): fixed by https://github.com/doctrine/orm/pull/11453
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7367