Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Looked a bit but didn't see an issue about this, sorry if I missed it.
An ugly mysql message can be produced when $vids ends up being empty
Problem area
function pre_render($values) {
// If there are no values to render (displaying a summary, or query returned no results),
// or if this is not a grouped field, do nothing specific.
if (isset($this->view->build_info['summary']) || empty($values) || !$this->defer_query) {
return parent::pre_render($values);
}
$field = $this->content_field;
$db_info = content_database_info($field);
$options = $this->options;
// Build the list of vids to retrieve.
// TODO: try fetching from cache_content first ??
$vids = array();
$this->field_values = array();
foreach ($values as $result) {
if (isset($result->{$this->field_alias})) {
$vids[] = $result->{$this->field_alias};
}
}
The thing actually producing the mysql error
" WHERE vid IN (". implode(',', $vids) .')'.
since $vids is empty the query contains vid IN (), which mysql doesn't like.
I changed to using this instead so I can test for empty vids
$vids = array();
foreach ($values as $result) {
if (isset($result->{$this->field_alias})) {
$vids[] = $result->{$this->field_alias};
}
}
if (isset($this->view->build_info['summary']) || empty($values) || !$this->defer_query || !$vids) {
return parent::pre_render($values);
}
$field = $this->content_field;
$db_info = content_database_info($field);
$options = $this->options;
// Build the list of vids to retrieve.
// TODO: try fetching from cache_content first ??
$this->field_values = array();
My erroring view is a user view with information from content profiles, which don't necessarily exist for some users.
Comment | File | Size | Author |
---|---|---|---|
#2 | membersview.txt | 8.88 KB | hefox |
Comments
Comment #1
markus_petrux CreditAttribution: markus_petrux commentedI have tried to create a view with a multiple values fields that does not exist for some node and I had no problem. The pre_render() method didn't use that query when the view does not return data ($values is empty). When $values is not empty, there's at least one vid, so that query where the condition is vid IN (...) doesn't fail. So I was not able to reproduce the problem.
Could you please export your view and attach here in txt format?
Comment #2
hefox CreditAttribution: hefox commentedThe view is of users (not nodes), ie on view creation "Users" was selected instead of "Nodes". It has a relationship to content profile node content profile though, so it's possible to have values, ie from the users like name etc., but not a VIDs if the users hasn't created a profile yet.
Comment #3
markus_petrux CreditAttribution: markus_petrux commentedI was able to reproduce the problem. Indeed, it may happen when a non-required relationship is involved.
Committed a patch to CCK2 and CCK3 branches. Thank you.