Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Code
Priority:
Minor
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Feb 2006 at 03:52 UTC
Updated:
14 May 2006 at 01:37 UTC
I have observed the following error in my logs:
Invalid argument supplied for foreach() in /.../sites/default/modules/views/views_query.inc on line 123.
views_query.inc on line 123 looks like:
foreach ($view->sort as $i => $sort) {
This is in function _views_view_build_sorts(). I guess it is called even when no sort options have been specified?
I have fixed my copy by adding a check at the begining of that function:
/*
* Add sorting information from a view to a query.
*/
function _views_view_build_sorts(&$query, $view) {
if (empty($view->sort)) {
return;
}
$sorts = _views_get_sorts();
foreach ($view->sort as $i => $sort) {
...
...
...
Comments
Comment #1
merlinofchaos commentedThis isn't the correct solution;
When a $view is loaded or otherwise created from within views, it should be sanitized to ensure that all arrays exist. This means that somehow a view is getting to this part of the code without this sanitize function being run on it, and that could indicate a bigger problem than simply the array not existing.
One more thing to look into when I have more free time again.
Comment #2
markus_petrux commentedI've found the same error related to the foreach loops in _views_view_build_filters() and _views_build_query().
It looks like, for some reason, _views_build_query() should perform some validations before doing its work.
This is probably my fault when calling the views_build_view() API with an invalid $view.
Comment #3
merlinofchaos commentedAhh, this likely means that views_build_view should be and is not calling...I think it is _views_check_arrays() or something like that. Which is a good idea since a view can come from an external source and we should ensure that the view is valid.
Comment #4
markus_petrux commentedI found my error. I was not checking if the result from calling views_get_view() was valid.
Well, I hope my mistake helps someone else. :-)
Comment #5
merlinofchaos commentedHmmm. Make me wonder if I should make views_build_view a little smarter and check that, or at least crash in a way that makes it obvious that the view was invalid.
I'm torn on this one, and will ruminate on it for awhile.
Comment #6
merlinofchaos commentedDecided that programmer error is just going to lead to stuff like this.