oroinc / platform

Main OroPlatform package with core functionality.
Other
627 stars 351 forks source link

QueryBuilder: Error: 'filter__gpnpmultiEnum2' is already defined. (tested on demo.orocrm.comn) #1039

Open sadortun opened 3 years ago

sadortun commented 3 years ago

Summary
A new issue has been introduced between 4.1.5 and 4.1.8, and is also present on https://demo.orocrm.com/

When Applying a segment, query is not processed correctly.

[Semantical Error] line 0, col 1993 near 'filter__gpnpmultiEnum2': Error: 'filter__gpnpmultiEnum2' is already defined. in /var/www/orocrm/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:65

~My guess is the issue was introduced in b1516a322e2a1de326ebeea5874bbcdc6048337c~

UPDATE : Did some investigation and issue is caused by 7e6c6e3

/cc @AlexandrDmitriev

EDIT : Reformat for clarity

Steps to reproduce

1) Edit any contact and set Contact Method Phone

2) Create a segment Test SUB image

3) Create a segment Test WITH RESULTS BUT WRONG

image

OUTPUT :

image

4) Create a segment Test NO RESULTS image

OUTPUT : image

5) Create a segment Test WITHOUT SEGMENT

image

OUTPUT image

[Semantical Error] line 0, col 1993 near 'filter__gpnpmultiEnum2': Error: 'filter__gpnpmultiEnum2' is already defined. in /var/www/orocrm/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:65

Actual Result

Test NO RESULTS

Getting grid data failed.

  exception: "Doctrine\ORM\Query\QueryException: 

QUERY : 
SELECT
    t1.id
FROM
    Oro \ Bundle \ ContactBundle \ Entity \ Contact t1
WHERE
    t1.id IN(
    SELECT
        ts1443173037.id
    FROM
        Oro \ Bundle \ ContactBundle \ Entity \ Contact ts1443173037
    WHERE
        ts1443173037 IN(
        SELECT
            filter__gpnpmultiEnum2
        FROM
            Oro \ Bundle \ ContactBundle \ Entity \ Contact filter__gpnpmultiEnum2
        INNER JOIN filter__gpnpmultiEnum2.myField filter__gpnpmultiEnum3_rel
        WHERE
            filter__gpnpmultiEnum3_rel IN(:_gpnpmultiEnum1)
    ) AND ts1443173037.id IN(
    SELECT
        ts1845229959.id
    FROM
        Oro \ Bundle \ ContactBundle \ Entity \ Contact ts1845229959
    WHERE
        ts1845229959 NOT IN(
        SELECT
            filter__gpnpmultiEnum2
        FROM
            Oro \ Bundle \ ContactBundle \ Entity \ Contact filter__gpnpmultiEnum2
        INNER JOIN filter__gpnpmultiEnum2.myField filter__gpnpmultiEnum3_rel
        WHERE
            filter__gpnpmultiEnum3_rel IN(:_gpnpmultiEnum1)
    )
)
)

 in /var/www/orocrm/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:43

`Test WITH RESULTS BUT WRONG

A Contact is found BUT SHOULD NOT since NO contacts have Contact Method set at BOTH Phone and Email at the same time

Test WITHOUT SEGMENT

Ok, Good. No result shown as expected, and no error. All 3 segments should be identical

Expected Result

Order of OP when using AND operands should not mather, or produce error.

a AND b should provide the same result as b AND a

Details about your environment

mbessolov commented 3 years ago

Thank you for reporting the issue.

(internal reference: BAP-20190)

sadortun commented 3 years ago

@mbessolov Did some investigation and issue is caused by 7e6c6e326c358ca01178da868a80b98ae45e7d78

Sorry @AlexandrDmitriev

/cc @x86demon