Problem/Motivation

\Drupal\Core\Entity\Query\Sql\Query::__toString() omits the alter() call that execute() makes. The string therefore lacks all alter-hook additions and does not represent the executed query.

Steps to reproduce

Look at the output of (string) $query for an entity query that has been altered via hook_entity_query_alter() and notice the alterations are not there.

Proposed resolution

Fix it :)

Remaining tasks

Review.

User interface changes

Nope.

Introduced terminology

N/A

API changes

Nope.

Data model changes

Nope.

Release notes snippet

N/A

Issue fork drupal-3593346

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

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative

Ran the test-only locally since I can't in the pipeline

Failed asserting that 'SELECT "base_table"."revision_id" AS "revision_id", "base_table"."id" AS "id"\n
FROM\n
"test69348519entity_test_mulrev" "base_table"\n
INNER JOIN "test69348519entity_test_mulrev__dlirhh2q" "entity_test_mulrev__dlirhh2q" ON "entity_test_mulrev__dlirhh2q"."entity_id" = "base_table"."id" AND "entity_test_mulrev__dlirhh2q"."langcode" = 'tr'\n
INNER JOIN "test69348519entity_test_mulrev__yuwvr5ms" "entity_test_mulrev__yuwvr5ms" ON "entity_test_mulrev__yuwvr5ms"."entity_id" = "base_table"."id"\n
WHERE ("entity_test_mulrev__dlirhh2q"."dlirhh2q_value" IS NOT NULL) AND ("entity_test_mulrev__yuwvr5ms"."yuwvr5ms_color" = 'red')\n
ORDER BY "base_table"."id" ASC' matches PCRE pattern "/<>\s*'5'/".
/var/www/html/core/tests/Drupal/KernelTests/Core/Entity/EntityQueryTest.php:143

Change itself looks fine. My only open question is if this needs a CR? It is a bug so people may assume it works but not sure. Won't hold the ticket up though.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Left a question on the MR

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for reviewing, @larowlan! Answered and fixed your point :)

@smustgrave, I don't think this needs a CR.

  • larowlan committed 55aa4066 on 11.x
    fix: #3593346 Entity query __toString() does not invoke the query alter...

  • larowlan committed ed5dfebd on main
    fix: #3593346 Entity query __toString() does not invoke the query alter...

  • larowlan committed 8054d99e on 11.4.x
    fix: #3593346 Entity query __toString() does not invoke the query alter...
larowlan’s picture

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

Committed and pushed ed5dfebdddc to main and 55aa4066c86 to 11.x. Backported to 11.4.x.

Thanks!

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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.