Drupal filters are not using the mapped fields in SQL query

Created on 23 January 2023, over 1 year ago
Updated 26 January 2023, over 1 year ago

Problem/Motivation

@janes_p (from issue #3331171) wrote:

I have changed the SQL statements to fully qualified statements as per your documentation, to be on the safe side (and I cleared caches thereafter):

Read - SELECT p.provider_id, p.provider_name, p.provider_description, p.provider_identifier FROM {1:provider} p WHERE p.provider_id = :id
List - SELECT p.provider_id, p.provider_name FROM {1:provider} p WHERE TRUE :filters
Count - SELECT COUNT(1) FROM {1:provider} p

Still the same error message:

Query failed: SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: ...e FROM "plan_e"."provider" p WHERE TRUE ORDER BY id ASC LIM... ^: SELECT p.provider_id, p.provider_name FROM "plan_e"."provider" p WHERE TRUE ORDER BY id ASC LIMIT 100; Array ( )

Looks like the placeholder id is used in the :filters instead of the column name provider_id, or maybe the colon is missing in front of id.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France guignonv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @guignonv
  • Status changed to Fixed over 1 year ago
  • πŸ‡«πŸ‡·France guignonv

    @janes_p, this is not a bug, it's something that has not been configured. When you edit your external entity type, you sometimes need to specify the filter mapping as well. It's not needed when you just use your external entities with Drupal default features but since you are using the external entity in Search API, you need to do that. It's a setting to expend on the "storage" tab of your external entity, just below the "LIST" query.

    You should map it to "provider_id" in your case (sa shown on the picture).

    But since, once again, it is not obvious, I'll commit a patch that will provide a default mapping so you won't have to enter twice the same mapping, and I will rename "Filter mappings" to "Filter mapping overrides"... and it will work by default in your case.

  • πŸ‡¨πŸ‡­Switzerland janes_p Zurich

    Thanks, @guignonv - this is indeed not obvious and almost impossible to figure out without assistance. That's why documentation and/or generating reasonable defaults for simple cases is so important for a wider usage of this otherwise very useful module!

    It appears there is sill a quirk in the code - after having configured the filter fields as per your hint (and cleared numerous caches) I am still getting the same error message when I am calling Search API for indexing:

    Query failed: SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: ...e FROM "plan_e"."provider" p WHERE TRUE ORDER BY id ASC LIM... ^: SELECT p.provider_id, p.provider_name FROM "plan_e"."provider" p WHERE TRUE ORDER BY id ASC LIMIT 100; Array ( )

  • πŸ‡«πŸ‡·France guignonv

    Could you try with the "dev" version? Maybe a code update is needed. Once you've got the dev version, try clearing the settings of "Filter mapping overrides" (just use default behavior introduced in the last dev version).

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡­Switzerland janes_p Zurich

    Thanks, @uignov - no more error with indexing based on the dev version (and filter left on default, e.g. empty) 😊.

    The indexing process reports 1030 indexed entries for my provider table. I have yet to figure out how to retrieve and validate the indexed entries. I will keep you posted.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024