empty query executed when view argument is missing
| Project: | Views |
| Version: | 4.7.x-1.5 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
This very well could be my ignorance and not a bug, but here is the description.
I have a view used primarily for use in blocks. The blocks present lists of nodes tagged with a term within a certain vocabulary.
In order to enable the "more link" for these blocks, I have enabled 'page' for this same view.
Let's call the vocabulary as well as the view's page url 'color'. if i go to color/red, i see expected content tagged 'red'. In the breadcrumb there is a link back up to 'color'. If I select that, I end up with a stack trace and an SQL error:
1 {main}() /var/www/html/advo/index.php:0
2 menu_execute_active_handler() /var/www/html/advo/index.php:15
3 call_user_func_array () /var/www/html/advo/includes/menu.inc:418
4 views_view_page() /var/www/html/advo/includes/menu.inc:418
5 views_build_view() /var/www/html/advo/modules/views/views.module:520
6 pager_query() /var/www/html/advo/modules/views/views.module:655
7 db_query() /var/www/html/advo/includes/pager.inc:73
8 _db_query() /var/www/html/advo/includes/database.inc:197
9 trigger_error () /var/www/html/advo/includes/database.mysql.inc:120
1 {main}() /var/www/html/advo/index.php:0
2 menu_execute_active_handler() /var/www/html/advo/index.php:15
3 call_user_func_array () /var/www/html/advo/includes/menu.inc:418
4 views_view_page() /var/www/html/advo/includes/menu.inc:418
5 views_build_view() /var/www/html/advo/modules/views/views.module:520
6 pager_query() /var/www/html/advo/modules/views/views.module:655
7 db_query() /var/www/html/advo/includes/pager.inc:73
8 _db_query() /var/www/html/advo/includes/database.inc:197
9 trigger_error () /var/www/html/advo/includes/database.mysql.inc:120If my view (either block or page) is called without an arg, i'd expect it to provide the 'default' result, which in my case is the 'view empty text' option. but i don't believe that views should be attempting to execute a query when it hasn't been given sufficient info to assemble a query to begin with.

#1
Uh, in the argument there's a dropdown for the default behavior when the argument is missing. One of the options is 'use empty text'. The behavior you describe conforms to the "Display all values" default. If it were a snake it woulda bit ya.
#2
I am getting the exact same problem on my views that are not passed arguments. I have set the argument "Default" to be "Use Empty Text", but whenever i access the page without an argument that error is produce (the empty text is displayed fine).
I'm using version 1.5 for Drupal 4.7.
I had a look at the code for the function views_build_view and saw that it was calling the function _views_build_query. In this function it deals with the argdefault value as such (7 being the value for Use Empty Text):
case 7:// to trigger empty text, send back an empty query
$info['query'] = NULL;
return $info;
So it returns an empty query.
But then, further down in the views_build_view function, it rewrites the query (line 719 - still empty), and executes it on line 731. It does not check it if is not empty at all.
I added this code at line 731 and it doesn't produce the error anymore:
if (!empty($query)) {$result = ($limit ? db_query_range($query, $info['args'], $page * $limit + $offset, $limit) : db_query($query, $info['args']));
}
I dont know if that code will have problems in other sections, so i'd like some guidance as to whether that is a good solution to the problem.
Thanks!
#3
This is bug looks to be a duplicate of http://drupal.org/node/114028
#4
Damn. Views is too big. I completely forgot about that case. This will be fixed in 1.6
#5