Problem/Motivation

I have a glossary view that displays a list of taxonomy terms sorted alphabetically and offers a navigation with letters to click on. Just as in the default Glossary View provided by the module, the main view uses a context filter to filter taxonomy terms by their first letter. In case no argument is provided, a default argument is defined ("a" in my case).

After upgrading to 7.x-3.26 the other day, the view stopped working (no output). In the views admin using preview, I get an error message:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IN('A')) )AND(( (taxonomy_term_data.vid IN ('4')) )))) subquery' at line 7

It seems that the origin of the error is a double IN statement in the SQL query. In 7.x-3.25 it reads as follows:

SELECT taxonomy_term_data.name AS taxonomy_term_data_name, taxonomy_term_data.vid AS taxonomy_term_data_vid, taxonomy_term_data.tid AS tid, taxonomy_vocabulary.machine_name AS taxonomy_vocabulary_machine_name
FROM 
{taxonomy_term_data} taxonomy_term_data
LEFT JOIN {taxonomy_vocabulary} taxonomy_vocabulary ON taxonomy_term_data.vid = taxonomy_vocabulary.vid
WHERE (( (SUBSTRING(taxonomy_term_data.name, 1, 1) = 'A') )AND(( (taxonomy_term_data.vid IN  ('4')) )))
ORDER BY taxonomy_term_data_name ASC
LIMIT 100 OFFSET 0

In 7.x-3.26 and 7.x-3.x-dev it is (note the repeated IN statement in the line starting with WHERE):

SELECT taxonomy_term_data.name AS taxonomy_term_data_name, taxonomy_term_data.vid AS taxonomy_term_data_vid, taxonomy_term_data.tid AS tid, taxonomy_vocabulary.machine_name AS taxonomy_vocabulary_machine_name
FROM 
{taxonomy_term_data} taxonomy_term_data
LEFT JOIN {taxonomy_vocabulary} taxonomy_vocabulary ON taxonomy_term_data.vid = taxonomy_vocabulary.vid
WHERE (( (SUBSTRING(taxonomy_term_data.name, 1, 1) IN IN('A')) )AND(( (taxonomy_term_data.vid IN  ('4')) )))
ORDER BY taxonomy_term_data_name ASC
LIMIT 100 OFFSET 0

It seems the error is due to commit a15f92bc (#2977851: PHP 7.2: count() on non-Countable in views_many_to_one_helper). When I change if (is_array($value)) { in line 1080 back to if (count($value) > 1) {, the view works fine again.

Steps to reproduce

  1. Create a Glossary View showing taxonomy terms ordered alphabetically
  2. Add default argument for the context filter of the main view

Proposed resolution

Look for a better solution than the one fixing the Problem in Issue #2977851: PHP 7.2: count() on non-Countable in views_many_to_one_helper.

Remaining tasks

Find a solution that both fixes #2977851: PHP 7.2: count() on non-Countable in views_many_to_one_helper and does not break Glossary View.

User interface changes

No.

API changes

Not that I am aware of.

Data model changes

Not that I am aware of.

Comments

yan created an issue. See original summary.

yan’s picture

Version: 7.x-3.26 » 7.x-3.x-dev
Component: Miscellaneous » Code
brandonpost’s picture

Hi yan, thanks for finding the source of this problem. I posted a patch on the original issue at https://www.drupal.org/project/views/issues/2977851#comment-14663079.

yan’s picture

Thanks a lot, brandonpost!

DamienMcKenna’s picture

Let's fix this in #2977851.