SqlContentEntityStorage manager generates incorrect SQL

Created on 22 February 2020, almost 5 years ago
Updated 18 June 2024, 6 months ago

I have an ContentEntityType with fields 'remote_id' and 'source'. Both are in the Postgresql database as 'character varying' fields. I execute the following using 'drush php':

$sm = \Drupal::entityTypeManager()->getStorage('product');
$sm->loadByProperties(['remote_id' => '7', 'source' => 'finibar' ]);

I turn on database logging at the Postgresql level and see that the generated
query is

SELECT base_table.id AS id, base_table.id AS base_table_id
	   FROM
	   product base_table
	   INNER JOIN product product ON product.id = base_table.id
	   WHERE ((LOWER(product.remote_id) IN (LOWER('7')))) AND
      ((LOWER(product.source) IN (LOWER('7'))))

Note that the value that 'product.source' is tested against is not 'finibar' but is '7'.

loadByProperties does work, if both fields are integers, or one is a string and the
other is an integer. It does not work if both fields are strings.

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
DatabaseΒ  β†’

Last updated 2 days ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡ΊπŸ‡ΈUnited States lydianblues

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

Not all content is available!

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

  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Tried this on MySQL with the node table, and querying the 'title' and 'type' fields, and that works as expected.

    So there is something else going on than just loadByProperties not being able to handle two strings.

    Is the custom entity doing something special? Does it have it's own entity storage that does something? Is it only a problem on postgres?

    I looked at the code and all it does is cast values to arrays, so that should matter.

Production build 0.71.5 2024