entityQuery is broken on PostgreSQL when using array of values with case insensitive properties

Created on 20 August 2023, 10 months ago

Problem/Motivation

The patch from the parent issue works perfectly for ::loadByProperties() as it expects and array of values ​​and will add IN operator, in my case I am facing the same problem using ::entityQuery(),

Steps to reproduce

Being more specific, I'm working with the menu_export module (and PostgreSQL of course) and it has this query:

      $menuLinkEntity = \Drupal::entityQuery('menu_link_content')
        ->accessCheck(FALSE)
        ->condition('uuid', $menu['uuid'])
        ->execute();

Where $menu['uuid'] is an array of values.

The problem with this is that the condition operator is not defined, and when the translateCondition() is executed, it didn't add the operator, which should be "IN", causing this error:

SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "("
LINE 5: WHERE (LOWER("menu_link_content"."uuid")  (LOWER('XXXXX

Proposed resolution

Not sure if it should be a core or module issue, I added a patch that worked for me.

I added the IN operator if $condition['operator'] is empty:

      if (empty($condition['operator'])) {
        $condition['operator'] = 'IN';
      }

I didn't have enough time to add a test, it would be something like this:

    $node1 = $this->drupalCreateNode([
      'type' => 'page',
      'field_first' => '1234',
      'field_second' => 'test_value_1',
    ]);
    $nodes = $this->container->get('entity_type.manager')->getStorage('node')->getQuery()->condition('uuid',[$node1->uuid()])->execute();
    // @todo validate results
πŸ› Bug report
Status

Active

Version

9.5

Component
PostgreSQL driverΒ  β†’

Last updated 6 days ago

No maintainer
Created by

πŸ‡²πŸ‡½Mexico luisnicg

Live updates comments and jobs are added and updated live.
  • PostgreSQL

    Particularly affects sites running on the PostgreSQL database.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024