entityQuery returns incorrect results if fields don't exist

Created on 18 August 2020, over 4 years ago
Updated 15 June 2023, over 1 year ago

Problem/Motivation

When doing a Drupal::entityQuery() that involves OR operations, the query is built incorrectly and results all records in situations where there should be zero records.

Steps to reproduce

Have an entity type with several optional link fields.
Create example entities with some of these fields filled in.
Create a query using Drupal::entityQuery() that searches each field

  $query = \Drupal::entityQuery($entity_type, 'OR');
  foreach ($field_names as $field_name) {
      $query->condition($field_name, $needle . '%', 'LIKE');
    }
  }
  return $query->execute();

In the situation where the $needle doesn't exist in any of the entities, it will return a list of all entities of that type.

However, if you do separate queries for each of the conditions and combine the results you get different results.

Proposed resolution

Fix the database system.

Remaining tasks

  • Write a test to show the problem.
  • Identify the source of the problem.
  • Fix the problem.

User interface changes

n/a

API changes

tbd

Data model changes

n/a

Release notes snippet

tbd

🐛 Bug report
Status

Active

Version

9.5

Component
Database 

Last updated 2 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇺🇸United States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024