Discriminator column condition SQL contains empty string when inheritance tree contains an abstract class non-root entity #7303

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

Originally created by @DemoniacDeath on GitHub (Jan 31, 2024).

BC Break Report

Q A
BC Break yes
Version 2.14.2

Summary

after commit 4e8e3ef30b when \Doctrine\ORM\Query\SqlWalker generates dicsriminator column condition SQL (method \Doctrine\ORM\Query\SqlWalker::generateDiscriminatorColumnConditionSQL) it adds an empty string to the list of possible values if the inheritance hierarchy contains a non-root abstract class. when the discriminator column is implemented with a custom type in PostgreSQL (equivalent of Enum) the query fails because the type cannot have a value of an empty string. it boils down to the fact that \Doctrine\ORM\Mapping\ClassMetadataInfo::$subClasses contains an abstract class and in it's Metadata the value of \Doctrine\ORM\Mapping\ClassMetadataInfo::$discriminatorValue is null.

Previous behavior

In version 2.14.1 \Doctrine\ORM\Mapping\ClassMetadataInfo::$subClasses does not contain an abstract class.

Current behavior

As described in Summary

How to reproduce

Here are entity definitions necessary to reproduce the problem.

/**
 * @ORM\Entity()
 * @ORM\Table(name="bug")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="asset_type", type="string")
 * @ORM\DiscriminatorMap({
 *     "foo" = "\Doctrine\Tests\ORM\Functional\Ticket\BugFoo",
 *     "bar" = "\Doctrine\Tests\ORM\Functional\Ticket\BugBar",
 *     "baz" = "\Doctrine\Tests\ORM\Functional\Ticket\BugBaz",
 * })
 */
class BugRoot
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Column(type="integer")
     *
     * @var int|null
     */
    private $id = null;
}

/**
 * @ORM\Entity()
 */
abstract class BugParent extends BugRoot
{
}

/**
 * @ORM\Entity()
 */
class BugFoo extends BugParent
{
}

/**
 * @ORM\Entity()
 */
class BugBar extends BugParent
{
}

/**
 * @ORM\Entity()
 */
class BugBaz extends BugRoot
{
}

The simplest way to reproduce the problem is

class BugTest extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->setUpEntitySchema([
            BugRoot::class,
            BugParent::class,
            BugFoo::class,
            BugBar::class,
            BugBaz::class,
        ]);
    }

    public function testBug(): void
    {
        $this->getEntityManager()->createQuery('SELECT e FROM ' . BugRoot::class . ' e')->getSQL();
    }
}

if run from tag 2.14.2 the execution fails with
PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated which is caused by the issue described in Summary. If the deprecation is skipped, like it is in our production code, the empty string is added to discriminator column condition SQL.

when I have time I'll try to create a reproducer which ties directly to method generateDiscriminatorColumnConditionSQL

Originally created by @DemoniacDeath on GitHub (Jan 31, 2024). ### BC Break Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | yes | Version | 2.14.2 #### Summary after commit https://github.com/doctrine/orm/commit/4e8e3ef30b3d214640883aec5a17896afc006116 when `\Doctrine\ORM\Query\SqlWalker` generates dicsriminator column condition SQL (method `\Doctrine\ORM\Query\SqlWalker::generateDiscriminatorColumnConditionSQL`) it adds an empty string to the list of possible values if the inheritance hierarchy contains a non-root abstract class. when the discriminator column is implemented with a custom type in PostgreSQL (equivalent of Enum) the query fails because the type cannot have a value of an empty string. it boils down to the fact that `\Doctrine\ORM\Mapping\ClassMetadataInfo::$subClasses` contains an abstract class and in it's Metadata the value of `\Doctrine\ORM\Mapping\ClassMetadataInfo::$discriminatorValue` is `null`. #### Previous behavior In version 2.14.1 `\Doctrine\ORM\Mapping\ClassMetadataInfo::$subClasses` does not contain an abstract class. #### Current behavior As described in Summary #### How to reproduce Here are entity definitions necessary to reproduce the problem. ```php /** * @ORM\Entity() * @ORM\Table(name="bug") * @ORM\InheritanceType("SINGLE_TABLE") * @ORM\DiscriminatorColumn(name="asset_type", type="string") * @ORM\DiscriminatorMap({ * "foo" = "\Doctrine\Tests\ORM\Functional\Ticket\BugFoo", * "bar" = "\Doctrine\Tests\ORM\Functional\Ticket\BugBar", * "baz" = "\Doctrine\Tests\ORM\Functional\Ticket\BugBaz", * }) */ class BugRoot { /** * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") * @ORM\Column(type="integer") * * @var int|null */ private $id = null; } /** * @ORM\Entity() */ abstract class BugParent extends BugRoot { } /** * @ORM\Entity() */ class BugFoo extends BugParent { } /** * @ORM\Entity() */ class BugBar extends BugParent { } /** * @ORM\Entity() */ class BugBaz extends BugRoot { } ``` The simplest way to reproduce the problem is ```php class BugTest extends OrmFunctionalTestCase { protected function setUp(): void { parent::setUp(); $this->setUpEntitySchema([ BugRoot::class, BugParent::class, BugFoo::class, BugBar::class, BugBaz::class, ]); } public function testBug(): void { $this->getEntityManager()->createQuery('SELECT e FROM ' . BugRoot::class . ' e')->getSQL(); } } ``` if run from tag 2.14.2 the execution fails with `PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated` which is caused by the issue described in Summary. If the deprecation is skipped, like it is in our production code, the empty string is added to discriminator column condition SQL. when I have time I'll try to create a reproducer which ties directly to method `generateDiscriminatorColumnConditionSQL`
admin closed this issue 2026-01-22 15:49:38 +01:00
Author
Owner

@mpdude commented on GitHub (Feb 3, 2024):

Fixed by #11200

@mpdude commented on GitHub (Feb 3, 2024): Fixed by #11200
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7303