Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens:

SELECT gc.entity_id AS entity_id FROM {group_content_field_data} gc WHERE type = :db_condition_placeholder_0:db_condition_placeholder_1; Array ( [:db_condition_placeholder_0] => group_content_type_5c237bd57772d [:db_condition_placeholder_1] => working_group-group_node-forum )

in Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (line 110 of /app/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php).

This query at /src/EventSubscriber/QueryAccessSubscriber.php is causing the problem

    $grouped_entity_ids = $this->database
      ->select('group_content_field_data', 'gc')
      ->fields('gc', ['entity_id'])
      ->condition('type', $group_content_type_ids)
      ->execute()
      ->fetchCol();

$group_content_type_ids is an array, and for my case, $group_content_type_ids it has 2 elements. When this query executed, it seems to concatenate two values to one, so it complains for number of bound variables does not match number of tokens

Comments

cyoon84 created an issue. See original summary.

fonant’s picture

Should be generating "WHERE type IN (:db_condition_placeholder_0, :db_condition_placeholder_1);" if the second condition argument is an array, I think? Perhaps we need to explicitly set "IN" as the comparison operator as a third argument to the ->condition() method?

cyoon84’s picture

cyoon84’s picture

@fonant yes, that's what I thought too. My just uploaded patch includes 'IN' in condition part.

cyoon84’s picture

Status: Active » Needs review
fonant’s picture

Patch from #3 fixes the problem for me here.

kristiaanvandeneynde’s picture

StatusFileSize
new5.44 KB

It's actually happening all over that function. Forgot the database layer requires you to be specific about IN queries. Going to try and adjust some tests so they would trigger these errors.

kristiaanvandeneynde’s picture

StatusFileSize
new26.83 KB

This fixes all sorts of issues. Affected tests went red without the changes and green with, let's see what the whole test suite has to say.

kristiaanvandeneynde’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.