Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discriminator column empty value "IN" query #10846

Closed
Legion112 opened this issue Jul 17, 2023 · 4 comments · Fixed by #11200
Closed

Discriminator column empty value "IN" query #10846

Legion112 opened this issue Jul 17, 2023 · 4 comments · Fixed by #11200

Comments

@Legion112
Copy link

Bug Report

Q A
BC Break no
Version 2.14.2

Summary

DiscriminatorMap adding empty value ('') to SQL query example:

Executing query: SELECT o0_.id AS id_0, o0_.amount AS amount_1, o0_.depositAddress AS depositAddress_2, o0_.name AS name_3, o0_.network AS network_4, o0_.type AS type_5 FROM operations o0_ WHERE o0_.type IN ('blockchain-in', 'expense', '')

This leads to error invalid input value when using Enum for Postgres DB

Current behavior

Adding o0_.type IN ('blockchain-in', 'expense', '') is incorrect and should be o0_.type IN ('blockchain-in', 'expense')

How to reproduce

I create a repository with an easy way to reproduce this issue.
It was introduced in version 2.14.2 prior to this version it was working as expected.

You could verify it by cloning the repository: https://github.com/Legion112/doctrine-playground
After cloning use docker for quick setup:

make shell 

After running the command below in logs you could see a wrong select statement

composer require doctrine/orm:2.14.2 -W && php index.php

I have confirmed that this version correctly was formatted correctly

Expected behavior

Executing query: SELECT o0_.id AS id_0, o0_.amount AS amount_1, o0_.depositAddress AS depositAddress_2, o0_.name AS name_3, o0_.network AS network_4, o0_.type AS type_5 FROM operations o0_ WHERE o0_.type IN ('blockchain-in', 'expense')
@JanTvrdik
Copy link
Contributor

This error comes from Doctrine\ORM\Query\SqlWalker::generateDiscriminatorColumnConditionSQL(), because the discriminatorValue of a intermediate subclass will be null.

It is most likely caused by #10411.

Similar issue already fixed: #10643


It also emits to following error:

Deprecated: PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated in /app/vendor/doctrine/dbal/src/Driver/PDO/Connection.php on line 84

@mpdude
Copy link
Contributor

mpdude commented Feb 2, 2024

Please report in #11200 whether it fixes this issue

@Legion112
Copy link
Author

I have installed the patched on my tested project
image
image

I have tested it on my playground and I confirm that the patch will fix the issue with IN statement.

image|

Some testing on real application could be done by my colleague @RalkeryBug
To test you would need to add fork repository:

    "repositories": [{
        "type": "vcs",
        "url": "https://github.com/DemoniacDeath/orm.git"
    }
    ],

Install the patch version

composer require doctrine/orm:dev-issue-11199 -W

Run the application test to make sure patch does not break anything else.

mpdude added a commit that referenced this issue Feb 3, 2024
…nator column condition SQL (#11200)

After commit 4e8e3ef 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 its 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.

Fixes #11199, fixes #11177, fixes #10846.
---------

Co-authored-by: Michael Skvortsov <michael.skvortsov@eleving.com>
Co-authored-by: Matthias Pigulla <mp@webfactory.de>
@mpdude mpdude added this to the 2.18.1 milestone Feb 3, 2024
@mpdude
Copy link
Contributor

mpdude commented Feb 3, 2024

Fixed by #11200

@mpdude mpdude closed this as completed Feb 3, 2024
@derrabus derrabus removed this from the 2.18.1 milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants