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

PostgreSQL JSONB contains operator is broken #1106

Open
alvaro-octal opened this issue Dec 31, 2020 · 3 comments
Open

PostgreSQL JSONB contains operator is broken #1106

alvaro-octal opened this issue Dec 31, 2020 · 3 comments

Comments

@alvaro-octal
Copy link

alvaro-octal commented Dec 31, 2020

BC Break Report

Q A
BC Break yes
Version 3.0.2

Summary

The migrations worked fine with 3.0.1, but version 3.0.2 seems to be trying to replace the ? PostgreSQL operand by $1 of queries like this:

UPDATE "user" u
SET permissions = permissions::jsonb || '["dashboard"]'::jsonb
WHERE (u.permissions_old->'dashboard'->'api')::jsonb ? 'read'

https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE

Previous behavior

This migration was valid

Current behavior

[error] Migration App\Migrations\Version20201023161652 failed during Execution. Error: "An exception occurred while executing '
            UPDATE "user" u
            SET permissions = permissions::jsonb || '["dashboard"]'::jsonb
            WHERE (u.permissions_old->'dashboard'->'api')::jsonb ? 'read'
        ':
SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "$1"
LINE 4: ...ERE (u.permissions_old->'dashboard'->'api')::jsonb $1 'read'
                                                              ^"
In AbstractPostgreSQLDriver.php line 73:
                                                                              
  An exception occurred while executing '                                     
              UPDATE "user" u                                                 
              SET permissions = permissions::jsonb || '["dashboard"]'::jsonb  
              WHERE (u.permissions_old->'dashboard'->'api')::jsonb ? 'read'   
          ':                                                                  
                                                                              
  SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "$1"       
  LINE 4: ...ERE (u.permissions_old->'dashboard'->'api')::jsonb $1 'read'     

How to reproduce

Make any migration with the ? operand on a PostgreSQL database on (at least) PHP 7.3

@goetas
Copy link
Member

goetas commented Dec 31, 2020

This is actually a PHP bug, solved in 7.4 by https://wiki.php.net/rfc/pdo_escape_placeholders (see also https://bugs.php.net/bug.php?id=71885)

@goetas goetas closed this as completed Dec 31, 2020
@goetas goetas reopened this Dec 31, 2020
@shadowhand
Copy link
Contributor

I do not believe this is purely a PHP bug. The same query works just fine in doctrine/migrations v3.0.1 and breaks in v3.0.2.

@adrianrudnik
Copy link

adrianrudnik commented Jan 6, 2021

Same happening here, just by upgrading to 3.0.2 on PHP 7.4.13.

I traced it down with xdebug to d3cf285#diff-234fe782577400df58580164cb830c2a2067c411c7a33f649a220719794d76fbL297 (takes while until it jumps).

Incoming params and types are an empty array.

The change from executeUpdate (deprecated, but using PDO statements) to executeQuery (using PDO query) introduced this bug. Most likely as query tries to analyze possible placeholders, while a statement needs them given as parameters.

The deprecation notice for executeUpdate also states the replacement should be executeStatement, not executeQuery.

Hope thats the right hunch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants