Problem/Motivation

When wrapping multiple OR groups inside an AND group in an entity query, you get the wrong (empty) results.

Steps to reproduce

1. Use a multi-value field, such as a term reference, on an entity that has terms from two vocabularies.
2. Build $and = $query->andConditionGroup() and add two orConditionGroup()s to it, each with a condition on that field.
3. Add $and to the query and execute it. It returns 0 results. Adding the same OR groups directly to $query returns the entity.

See the test.

Proposed resolution

Add a strtoupper for the AND conjunction, same as we have for the OR conjunction

Remaining tasks

Review and discuss

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

Issue fork drupal-3631067

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lendude created an issue. See original summary.

lendude’s picture

Status: Active » Needs review

Pushed a test and a fix.

Disclaimer: Used Claude to help write some stuff

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.
The code change has testing for it.
To me it is RTBC.

alexpott’s picture

Version: main » 11.5.x-dev
Status: Reviewed & tested by the community » Fixed

Nice find! I've searched the core codebase and confirmed that this is the only place we're not wrapping a comparison against a conjunction with strtoupper - for example we already do $and = strtoupper($this->conjunction) == 'AND'; in \Drupal\Core\Config\Entity\Query\Condition::compile()

Committed 4a2327e and pushed to main. Thanks!
Committed 8e8fb28 and pushed to 12.0.x. Thanks!
Committed 5910ba0 and pushed to 11.x. Thanks!
Committed d59c530 and pushed to 11.5.x. Thanks!

Backported to 11.5.x as a low risk and nice bug fix.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed d59c5305 on 11.5.x
    fix: #3631067 Entity query Condition::compile() compares the AND...

  • alexpott committed 5910ba0a on 11.x
    fix: #3631067 Entity query Condition::compile() compares the AND...

  • alexpott committed 8e8fb286 on 12.0.x
    fix: #3631067 Entity query Condition::compile() compares the AND...

  • alexpott committed 4a2327e8 on main
    fix: #3631067 Entity query Condition::compile() compares the AND...