Hi@all,
today I created a view with a grouped exposed filter on a list field. I have two exposed filter values which group two values of the field. This view produces the following invalide SQL:
SELECT node.created AS node_created, node.nid AS nid
FROM
{node} node
INNER JOIN {field_data_field_list_field} field_data_field_list_field ON node.nid = field_data_field_list_field.entity_id AND (field_data_field_list_field.entity_type = 'node' AND field_data_field_list_field.deleted = '0')
WHERE (( (node.status = '1') AND (node.type IN ('car')) AND (field_data_field_list_field.field_list_field_value = 'type1', 'type2') ))
ORDER BY node_created DESC
Wrong part:
(field_data_field_list_field.field_list_field_value = 'type1', 'type2')
The attached patch solves the proble for me.
Best regards
dendie
Comments
Comment #1
grasmash commentedI've experienced this problem in Views 7.x-3.7. It is caused by creating an exposed, grouped filter and selecting multiple values for one of the filter groups. This effectively breaks the view when such a filter value is selected.
I can verify that the attached patch does fix the issue. I've fixed the formatting issues in the patch and resubmitted.
Comment #2
chris matthews commentedThe 5 year old patch to handlers.inc applied cleanly to the latest views 7.x-3.x-dev and if still relevant needs review.
Comment #3
damienmckennaComment #4
damienmckennaSome tests were committed in #3040391: 3.21 Regression, malformed SQL: 'Is none of' within grouped exposed filter that should be extended for this. Thanks.
Comment #5
feyp commentedAttached is a new patch based on patch #1 that extends the test case added in #3040391: 3.21 Regression, malformed SQL: 'Is none of' within grouped exposed filter to cover this issue.
I also added a test based on the steps to reproduce in comment 25 of #2224601: Grouped exposed taxonomy term filters do not work, which is fixed by patch #1 as well.
Comment #13
damienmckennaCopying people from #2224601 who worked on a nearly identical patch.
Comment #14
damienmckennaWorking on the tests a little bit.
Comment #15
damienmckennaHere's an updated patch that extends the test coverage for additional checks. I added $this->verbose() output for two queries which I was concerned about. Could someone please look over it to make sure that the results are as expected? Thanks.
Comment #16
feyp commentedThank you Damien! I just looked at your changes and in principle, I think they are fine. A few observations, though, that I think are worth discussing:
In
testReducedExposedGroupedOptions():Spotting my very own mistake here...
tidshould bevalue. In hindsight, we can just remove the second line of each code block, since any array that is not empty should fail the assertion. Sorry for that!This is actually a duplicate of the test for Option 5: Empty. We can't assert Option 4: Is all of 1 and 2. at the moment due to #3045168: Empty where group with exposed filter and grouped 'is all of' option, hence the
@todo. Option 5: Empty is already tested further down in the test.testTermIdExposedGroupedOptions()We're not asserting the correct field values of the new node again here. Not sure if we should. I guess we can skip this.
Same as option 4 in the other test. This should return one result and it should be the new
$this->nodes[2]. It is empty now, since the query doesn't work the way it should. Not sure that we should really assert this result, just because it would preserve the current broken state until we fix the bug. I have some sympathy for it, since it would make sure that we won't accidentally start to return nodes that we shouldn't return. On the other hand it's just the wrong result. Also, I think that if we really do this, then we should do the same for option 4 in the other test, so that it is consistent at least.$this->assertEqual($result_count, 4, 'Option 4: View has four results.');$this->assertIdentical($result_count, 4, 'Option 7: View has four results.');This is debatable, but I think it's the expected result for the configuration we're using here. Should we assert, that all node ids are in the result set? Not sure. I guess it's unlikely, that we would end up with four results and not have all nodes in the result set, so I guess we can skip it.
I'd upload a new patch to correct my own mistake regarding the empty value of
field_list, but I'd be interested in your opinion on the other points, before I do so.Comment #17
damienmckenna@FeyP: Thanks for taking the time to review the changes. I think that any bugs identified, which are unrelated to this issue, should go into new issue(s), and those tests should be commented out for now; any bugs that are related to this issue should have the test coverage adjusted to show the failure and we can then work on further refining the logic. And I do think it's worth confirming that the node IDs are what we expect; it might be worth sorting the results by node ID, to make this easier to do.
Comment #18
feyp commentedThank you for following up so quickly! Attached is the updated patch:
field_list.Comment #19
damienmckennaThis is great, thank you FeyP!
braindrift and grasmash: Would you mind testing the latest patch to see if it resolves your site's problem(s)? Thank you.
Comment #20
damienmckennaCommitted. Thanks everyone!