QueryException while attempting to find indexed entities referencing changed Profile

Created on 13 September 2022, about 2 years ago
Updated 28 May 2023, over 1 year ago

Problem/Motivation

Steps to reproduce

  1. install search_api, and a few commerce modules: commerce,commerce_cart,commerce_checkout,commerce_log,commerce_number_pattern,commerce_order,commerce_payment,commerce_price,commerce_product,commerce_store
  2. create a db index
  3. for this db index set the Order datasource
  4. set billing_profile:entity:address:given_name as an indexed field
  5. create a product
  6. order that product
  7. go to the order and change the name in Billing info
  8. save the order
  9. there're multiple new log entries:

Drupal\Core\Entity\Query\QueryException while attempting to find indexed entities referencing changed Profile with ID "4" for index Order: 'billing_profile' not found in Drupal\Core\Entity\Query\Sql\Tables->ensureEntityTable() (line 369 of /app/web/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).

Proposed resolution

Remaining tasks

๐Ÿ› Bug report
Status

Needs review

Version

1.0

Component

General code

Created by

๐Ÿ‡ธ๐Ÿ‡ฐSlovakia kaszarobert

Live updates comments and jobs are added and updated live.
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.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update over 1 year ago
    538 pass
  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drunken monkey Vienna, Austria

    Thanks for reporting this issue, and sorry it took me so long to get back to you.
    I was able to reproduce the problem, but I donโ€™t think its root cause is actually in this module. It seems something is wrong with entity queries on the Order entity type โ€“ either a bug in Core or in Commerce.

    To be more precise, this is the query executed in your scenario:

    \Drupal::entityQuery('node')
      ->accessCheck(FALSE)
      ->condition('billing_profile.entity', 1)
      ->execute()
    

    It fails with โ€œ'billing_profile' not foundโ€, as you say.

    However, this logically equivalent query works:

    \Drupal::entityQuery('node')
      ->accessCheck(FALSE)
      ->condition('billing_profile', 1)
      ->execute()
    

    Itโ€™s not a very pretty solution, but I guess we can just change the query in the specific scenario to work again.
    The problem, of course, is that this will still fail the same way as before when a sub-field is used as the filter โ€“ e.g., billing_profile.entity.given_name. I therefore think we should, after applying this workaround to our module, move the issue to the Commerce issue queue. (Someone else recently created another issue regarding indexing of Order entities ( ๐Ÿ› Indexing commerce orders via Drush triggers OrderRefresh Active ), so it seems there is just something very peculiar about that entity type.)

    But for now, please see the attached patch and tell me if it fixes the problem for you!

Production build 0.71.5 2024