Hi,
When you /search/site/something_that_has_no_results, I get:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 '))' at line 1: SELECT u.uid AS uid, u.name AS name FROM {users} u WHERE (uid IN ()) ; Array ( ) in facetapi_map_author() (line 32 of /www/htdocs/sites/all/modules/contrib/facetapi/facetapi.callbacks.inc).

/**
 * Map callback for node authors.
 */
function facetapi_map_author(array $values) {
  $result = db_select('users', 'u')
    ->fields('u', array('uid', 'name'))
    ->condition('uid', $values, 'IN')
    ->execute();

debug shows an empty array, unlike when you have some results, in which case it is an array of user I.D.'s

CommentFileSizeAuthor
#3 mapvalues-empty-1399706-0.patch1.73 KBchrisyates

Comments

cpliakas’s picture

Title: Issues with facetapi_map_author » Mapping callbacks are invoked when there are no values to map leading to fatal errors in some callbacks

Hi SangersDrupalDude.

Thanks for the post. This is actually a regression introduced by the resolution to issue #1356962: Current Search block displays incorrect values when there are no search results which may effect more than just the author mapping callback. The old logic mapped values only when there were items in the render array, therefore when a search had no results there were no values to map. This logic was flawed and we moved the mapping functionality above the line checking whether there are items in the render array, and as a side effect there is now the possibility of passing an empty array to the mapping callback. Changing the title to reflect this information.

I think the solution here is to add a condition to the FacetapiFacetProcessor::mapValues() method testing whether the $values variable is empty prior to invoking the callbacks. Specifically, an if ($values = array_unique(array_keys($build + $this->getActiveItems()))) { should do the trick.

Placing this on the "low hanging fruit" list. Still looking for committer #20! Great way to get on the list.

Thanks,
Chris

cpliakas’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev

Moving back to a 7.x-1.x task.

chrisyates’s picture

Status: Active » Needs review
StatusFileSize
new1.73 KB

Patch for issue.

cpliakas’s picture

Status: Needs review » Reviewed & tested by the community

This looks great. Marking as RTBC.

cpliakas’s picture

Status: Reviewed & tested by the community » Fixed

Committed at http://drupalcode.org/project/facetapi.git/commit/46473fd.

Congrats on becoming the 20th code contributor to Facet API!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.