I added a entity reference field to a content type to hold unlimited values. For the "Reference method" I am using a entity reference view. I am using the widget autocomplete.

When I add more then one value I get the following exception:

Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Reservable Resources[reservable_resources]: SQLSTATE[HY000]: General error: 1 near ":db_condition_placeholder_5": syntax error: SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid FROM {node_field_data} node_field_data LEFT JOIN {node__field_reservable_by} node__field_reservable_by ON node_field_data.nid = node__field_reservable_by.entity_id AND (node__field_reservable_by.deleted = :views_join_condition_0 AND node__field_reservable_by.langcode = node_field_data.langcode) WHERE (( (node__field_reservable_by.field_reservable_by_target_id IN (:db_condition_placeholder_2, :db_condition_placeholder_3)) AND (nid = :db_condition_placeholder_4:db_condition_placeholder_5) )AND(( (node_field_data.status = :db_condition_placeholder_6) AND (node_field_data.type IN (:db_condition_placeholder_7)) ))) ORDER BY node_field_data_created DESC; Array ( [:db_condition_placeholder_2] => authenticated [:db_condition_placeholder_3] => administrator [:db_condition_placeholder_4] => 7 [:db_condition_placeholder_5] => 10 [:db_condition_placeholder_6] => 1 [:db_condition_placeholder_7] => merci_resource [:views_join_condition_0] => 0 ) in Drupal\views\Plugin\views\query\Sql->execute() (line 1457 of core/modules/views/src/Plugin/views/query/Sql.php).

I tracked this down to the following line in: core/modules/views/src/Plugin/views/display/EntityReference.php

// Add an IN condition for validation.
    if (!empty($options['ids'])) {
      $this->view->query->addWhere(0, $id_field, $options['ids']);
    }

I updated to add the "IN" operator to prevent the exception.

The docs say the "IN" operator is the default. But that's not happening on my system.

I am using SQLite 3.8.7.2 on OSX. Apache/2.2.29 (Unix) mod_wsgi/3.4 Python/2.7.8 PHP/5.6.7 mod_ssl/2.2.29 OpenSSL/0.9.8zg DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.8 Perl/v5.20.0

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

darrick created an issue. See original summary.

tusharbodke’s picture

Assigned: Unassigned » tusharbodke
darrick’s picture

Having same issue with MySQL 5.5.42. Operator is defaulting to '=' in public Condition::condition($field, $value = NULL, $operator = '=') function.

Api doc for Condition::condition state default is '=' while docs for Sql::addWhere states operator defaults 'IN' if $value is a array.

amateescu’s picture

Priority: Normal » Major
Status: Active » Needs review
FileSize
1.94 KB
3.59 KB

Ugh, this is pretty bad, a fatal error that happens for such a usual use case should be at least major.

The last submitted patch, 4: 2621782-test-only.patch, failed testing.

catch’s picture

Priority: Major » Critical
Status: Needs review » Reviewed & tested by the community

This looks like it was missed in the 8.x fix for https://www.drupal.org/SA-CORE-2014-005 - iirc we moved the array default for dynamic queries as part of that.

Since this is a fatal error that's easy to run into via the UI, bumping to critical.

Also the patch looks good to me, so moving to RTBC - but will give it time for objections before committing.

The last submitted patch, 4: 2621782-test-only.patch, failed testing.

darrick’s picture

Patch works well on my end. Thanks.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 7e80e5b on 8.1.x
    Issue #2621782 by amateescu: SQL::addWhere not defaulting to "IN"...

  • catch committed c642355 on
    Issue #2621782 by amateescu: SQL::addWhere not defaulting to "IN"...

Status: Fixed » Closed (fixed)

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