Fix the sub-query part in UserSelection::entityQueryAlter

Created on 6 May 2014, over 10 years ago
Updated 18 February 2023, almost 2 years ago

Context

You looked at the queries, which are identical but the values are not. If you look at those, you can see that it's doing a "'Anonymous' LIKE 'en'"...

The reason is one of the dark places of the database layer, ensuring unique placeholders, which is done by recursively precompiling queries and passing around a shared object/state that returns a unique ID every time it's called for each query.

This works all fine until we get to the very special and dark case of UserSelection::entityQueryAlter() which manually compiles a query condition and passes the global default connection and the current query in for the placeholder ID stuff. Combine this with the count query, which is really a nested selected and we're now inside the inner query, which is *not* the one that was used for the compilation, the outer query would be, so we re-start the placer ID counter and get a _0 placeholder. That is the same as the language condition is using, so we re-use that placeholder and use the first value instead of the one that we're adding.

A possible workaround might be to preg_replace() the placeholder with one that is unique, but that's ugly (not that the whole piece of code there isn't already ugly). I suggest you get Crell and DamZ in here, because AFAIK they came up with all this preExecute() fun (I was involved too, but not as much as they).

Problem/Motivation

As per @Crell (in #2144377-135: Entity reference autocomplete lists entity labels only in current content language ), pre-compiling a query is not supported and need to be fixed in UserSelection::entityQueryAlter

Proposed resolution

Prosed solution hints from @Crell on IRC:

01:22 Crell: That plugin needs to get the DB connection injected properly.
01:22 Crell: And then not use db_and()/db_or().
01:22 Crell: And then not precompile the string and hope it works.
01:23 Crell: Actually… Hm, can you get the connection from the $query?
01:23 Crell: I could see an argument that you may need to.
01:24 Crell: And this is that argument.  Because there is, or at least there was an issue to add, methods to the connection for and/or so that the functions were not necessary.

Remaining tasks

User interface changes

API changes

🐛 Bug report
Status

Needs work

Version

10.1

Component
Database 

Last updated 2 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇬🇧United Kingdom vijaycs85 London, UK

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    This was tagged for issue summary update and tests from what I can still need to happen

    Did not test yet.

Production build 0.71.5 2024