Problem/Motivation

Currently SearchApiViewsQuery::get_result_wrappers() uses the array key of the passed in $results as entity id. At least in some scenarios $results comes directly from the view results.
Unfortunately there's no guarantee that $results is keyed by the entity_id.
Please check following issue for further information: #1350814: EntityFieldHandlerHelper should not use views row_index as entity_id

Proposed resolution

Please see the attached patch for a possible solution.

Remaining tasks

Review attached patch.
Check if there are other locations where the row-index is used as entity_id.

User interface changes

none.

API changes

none.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Status: Needs review » Closed (works as designed)

We set the Views result ourselves, so I'm pretty sure we can guarantee that the row indexes are the entity IDs. Otherwise, please provide a counter-example and re-open.

The issue for the Entity API seems valid, though – I don't think this relation between row indexes and entity IDs is specified anywhere.

das-peter’s picture

Status: Closed (works as designed) » Needs review
Issue tags: +dvcs11

We set the Views result ourselves, so I'm pretty sure we can guarantee

No we can't - especially if you use some advanced use cases.
That's why I explicitly linked to views_content_plugin_style_ctools_context (see line 31-34) in #1350814: EntityFieldHandlerHelper should not use views row_index as entity_id.
This is what you can see there:

31 // Some engines like solr key results on ids, but rendering really expects
32 // things to be keyed exclusively by row index. Using array_values()
33 // guarantees that.
34 $this->view->result = array_values($this->view->result);

This means if I use this ctools plugin to output my content, it will actively reset the row_index.
And even if this behaviour could be interpreted as somehow special, it doesn't violate any definition - because there's no definition that row_index has to be a special value at all.
The provided patch would make the views integration immune from such changes.
Is there any reason why not to make the code more solid? Especially if there are no drawbacks of any kind, which seems to be the case here.

drunken monkey’s picture

Category: bug » task
Status: Needs review » Fixed

To be fair, with „there's no definition“ you can do pretty much anything in Views – but I do see your point, and even if I don't think it's a very sensible thing to do by the Ctools plugin, I guess there really is no harm in making our side more robust.

Committed your patch, thanks!

das-peter’s picture

Thank you very much for committing this :)

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