EntityCacheControllerHelper::entityCacheLoad may generate entity queries with different case sensitivity to core

Created on 24 July 2023, 11 months ago
Updated 28 September 2023, 9 months ago

Problem/Motivation

Running entitycache's test suite with sqlite reveals that the following two taxonomy tests fail:

testTaxonomyGetTermByName

fail: [Other] Line 981 of modules/taxonomy/taxonomy.test:
Term loaded with uppercased name.

fail: [Other] Line 985 of modules/taxonomy/taxonomy.test:
Term loaded with lowercased name.

As far as I can see this is because when core runs taxonomy_get_term_by_name() without entitycache, DrupalDefaultEntityController::load does this:

      // Build the query.
      $query = $this->buildQuery($ids, $conditions, $revision_id);

...which produces a select query with a condition along the lines of base.name LIKE "foo".

Whereas with entitycache enabled, \EntityCacheControllerHelper::entityCacheLoad does this:

    if ($conditions) {
      $query = new EntityFieldQuery();
      $query->entityCondition('entity_type', $controller->entityType);
      foreach ($conditions as $property_name => $condition) {
        // Note $condition might be multiple values, which are treated as OR
        // by default.
        $query->propertyCondition($property_name, $condition);

...where EntityFieldQuery::propertyCondition uses a default operator of = for the condition.

With MySQL this typically makes no difference, but with other database systems which are case sensitive by default, there's a difference in behaviour as a result of the different operators / SQL syntax.

Steps to reproduce

Run entitycache tests with sqlite (and probably postgres) e.g.:

---- EntityCacheTaxonomyTermTestCase ----


Status    Group      Filename          Line Function                            
--------------------------------------------------------------------------------
Fail      Other      taxonomy.test      981 TaxonomyTermTestCase->testTaxonomyG
    Term loaded with uppercased name.
Fail      Other      taxonomy.test      985 TaxonomyTermTestCase->testTaxonomyG
    Term loaded with lowercased name.

Proposed resolution

I suppose to fix this we'd need to do something like explicitly pass an appropriate operator to EntityFieldQuery::propertyCondition for certain conditions.

For example, this quick hack makes the tests pass:

      foreach ($conditions as $property_name => $condition) {
        // Note $condition might be multiple values, which are treated as OR
        // by default.
        $operator = NULL;
        if ($property_name == 'name') {
          $operator = 'LIKE';
        }
        $query->propertyCondition($property_name, $condition, $operator);
      }

However, we'd need to do something like actually look up the property name in the base table's schema to determine whether it's appropriate to set the operator to something other than the default.

Remaining tasks

Outlined above.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom mcdruid 🇬🇧🇪🇺

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