Error when Hierarchical Select in Views with exposed filters

margaridacarvalho - September 26, 2009 - 10:04
Project:Hierarchical Select
Version:6.x-3.x-dev
Component:Code - Taxonomy Views
Category:bug report
Priority:normal
Assigned:Unassigned
Status:fixed
Description

When integrated in a view with exposed filters, hierarchical select gives this error after clicking apply button (in page view):

* warning: Invalid argument supplied for foreach() in /Users/margaridacarvalho/mysites/clisb/sites/all/modules/views/includes/handlers.inc on line 680.
* user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 10' at line 5 query: SELECT node.nid AS nid, node.title AS node_title FROM node node WHERE LIMIT 0, 10 in /Users/margaridacarvalho/mysites/clisb/sites/all/modules/views/includes/view.inc on line 755.

#1

Wim Leers - September 26, 2009 - 11:23
Assigned to:Anonymous» Wim Leers
Status:active» postponed (maintainer needs more info)

You're using the latest development snapshot or CVS HEAD?

#2

margaridacarvalho - September 26, 2009 - 15:32

I'm using hierarchical select 6.x-3.x-dev.

#3

Wim Leers - September 27, 2009 - 00:56

Of which date? Because it automatically gets regenerated after each commit, but only every 12 hours.

#4

tpolyak - September 27, 2009 - 14:54

Same problem here.
I'm using the latest development snapshot (2009-Sep-25)

#5

margaridacarvalho - September 27, 2009 - 20:33

I'm also using the latest development snapshot, 2009-Sep-25.

#6

jaron - September 30, 2009 - 16:17

i have a similar problem. using the .dev from sep 30. i'm getting this error:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in /var/www/html/DDO/sites/all/modules/views/includes/handlers.inc on line 590.

#7

Wim Leers - October 1, 2009 - 15:53

I haven't had the time to look into this. I'll try to do that this weekend.

#8

rickherman - October 15, 2009 - 17:59

I have what appears to be a similar error:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/content/r/i/c/rickherman1/html/sites/all/modules/Views/includes/handlers.inc on line 590.

Interestingly, it only results when I have more than one exposed filter actually selected as the user would when doing a database lookup. If I only set one query condition, no error results. It does this only when at least one HS controlled exposed filter is set. No error occurs when using a dropdown/show hierarchy control setting for the filter. Even with the error, the resulting query appears to work (I have to do more data testing.) I've tried numerous settings in the HS query control for the filter and it doesn't seem to change anything. At this point, I'm going to use the module since it's so much easier for the user, but just turn the error writing off to the screen. Would be great to get it fixed. I'll join the chorus and say this is a tremendous module, and thanks to Mr. Leers and all who have helped.

I've included the following screenshots:

AttachmentSize
Dropdown Query 2 Filters No Error Msg.pdf 814.29 KB
HS Query No Error With One Filter.pdf 683.79 KB
HS Query Error With 2 Filters Selected.pdf 656.22 KB
HS Module Version.pdf 86.67 KB

#9

rickherman - October 15, 2009 - 18:03

A few more screenshots/files that may be of help in diagnosing.

AttachmentSize
HS Node Taxonomy Vocabularies.pdf 538.25 KB
HS Module Settings.pdf 951.57 KB
HS Views Query.txt 939 bytes
HS Views Setup.txt 8.44 KB

#10

filburt - October 15, 2009 - 22:16

Hi, same problem here - see attached file. Thanks for support!

Filburt

AttachmentSize
Error_HS_Views_Exposed_Filt.gif 11.06 KB

#11

Wim Leers - October 31, 2009 - 02:16
Category:support request» bug report

Could you please post the line on which an error is being reported?

It's very unlikely you did something wrong, probably it's a relatively hard to reproduce bug in HS Taxonomy Views.

#12

pipicom - November 1, 2009 - 15:18

same problem here

AttachmentSize
localhost-Avertiz-admin-build-views-edit-search_car_with_views.jpg 282.87 KB

#13

Wim Leers - November 1, 2009 - 17:01

Again, could you please post the code on that line in the file?

#14

filburt - November 1, 2009 - 18:00

Sorry, but I don't use the module at the moment.

#15

pipicom - November 2, 2009 - 12:37

Hello Wim,

Would you want me to post the lines of the "handlers.inc" file on views folder? It's a file at "views\includes\handlers.inc".
Please let me know what should I do to help you help us!

#16

Wim Leers - November 2, 2009 - 14:09

I know which file it is. But there are many different versions of that file and that's why I need you to tell me to copy/paste that line. Or post the file's CVS version.

Thanks :)

#17

pipicom - November 3, 2009 - 12:56

OK Wim here's the code..

Error: warning: array_merge() [function.array-merge]: Argument #1 is not an array in E:\wamp\www\Avertiz\sites\all\modules\views\includes\handlers.inc on line 590.

Code (views function):

/**
   * Add a table to the query.
   *
   * This is an advanced concept; not only does it add a new instance of the table,
   * but it follows the relationship path all the way down to the relationship
   * link point and adds *that* as a new relationship and then adds the table to
   * the relationship, if necessary.
   */
  function add_table($join = NULL, $alias = NULL) {
    // This is used for lookups in the many_to_one table.
    $field = $this->handler->table . '.' . $this->handler->field;

    if (empty($join)) {
      $join = $this->get_join();
    }

    // See if there's a chain between us and the base relationship. If so, we need
    // to create a new relationship to use.
    $relationship = $this->handler->relationship;

    // Determine the primary table to seek
    if (empty($this->handler->query->relationships[$relationship])) {
      $base_table = $this->handler->query->base_table;
    }
    else {
      $base_table = $this->handler->query->relationships[$relationship]['base'];
    }

    // Cycle through the joins. This isn't as error-safe as the normal
    // ensure_path logic. Perhaps it should be.
    $r_join = drupal_clone($join);
    while ($r_join->left_table != $base_table) {
      $r_join = views_get_table_join($r_join->left_table, $base_table);
    }

    // If we found that there are tables in between, add the relationship.
    if ($r_join->table != $join->table) {
      $relationship = $this->handler->query->add_relationship($this->handler->table, $r_join, $r_join->table, $this->handler->relationship);
    }

    // And now add our table, using the new relationship if one was used.
    $alias = $this->handler->query->add_table($this->handler->table, $relationship, $join, $alias);

    // Store what values are used by this table chain so that other chains can
    // automatically discard those values.
    if (empty($this->handler->view->many_to_one_tables[$field])) {
      $this->handler->view->many_to_one_tables[$field] = $this->handler->value;
    }
    else {
      $this->handler->view->many_to_one_tables[$field] = array_merge($this->handler->view->many_to_one_tables[$field], $this->handler->value);
    }

    return $alias;
  }

  function get_join() {
    return $this->handler->get_join();
  }

Line 590 is exactly this piece of the above code:

$this->handler->view->many_to_one_tables[$field] = array_merge($this->handler->view->many_to_one_tables[$field], $this->handler->value);

Please let me know should you need ANYTHING else and I will answer asap.

#18

mairav - November 8, 2009 - 05:29

Same problem, suscribing.

#19

trupal218 - November 18, 2009 - 01:45

subcribing

#20

jrao - November 18, 2009 - 09:34

The problem seems to be that views expect the handler value to be an array while hs_taxonomy_views_handler_filter_term_node_tid.inc only returns a single value. This problem would only show up if you have multiple exposed taxonomy filters in a view, and one of them is HS. I'm not certain where is the best place to fix this, but this seems to work: at line 216 of hs_taxonomy_views_handler_filter_term_node_tid.inc, replace

return parent::accept_exposed_input($input);

with
    $rc = parent::accept_exposed_input($input);
    if ($this->select_type_is_hierarchical_select() && !is_array($this->value)) {
      $this->value = array($this->value);
    }
    return $rc;

#21

Wim Leers - November 18, 2009 - 23:05
Title:error when hierarchical select in views with exposed filters» Error when Hierarchical Select in Views with exposed filters
Assigned to:Wim Leers» Anonymous
Status:postponed (maintainer needs more info)» needs review

@jrao: wow, great find! Thanks!

I've created a patch out of your proposed changes. Others, please review!

AttachmentSize
588612-21.patch 1004 bytes

#22

VTM - November 19, 2009 - 12:53

WORKING OK !!!

(I have 2 filters, replaced the code lines as jaro offered , did not applied the patch yet)

Thank you jaro and Wim.

#23

Wim Leers - November 19, 2009 - 20:44
Status:needs review» fixed

Good enough for me. Committed: http://drupal.org/cvs?commit=291402.

Thanks!

#24

mairav - November 21, 2009 - 14:32

I thought I've wiritten here... maybe I dindn't push the Save button.
It worked for me too!

#25

Wim Leers - November 21, 2009 - 15:22

Great, another confirmation, thanks mairav! That means it should now be working for everybody.

 
 

Drupal is a registered trademark of Dries Buytaert.