Synopsis
If you have an attachment display that inherits exposed filters from another display and both displays share an exposed filter on a taxonomy term that has the Reduce duplicates setting enabled, the attachment display will not show any results, if the exposed taxonomy term filter is used.
Discussion
This is a regression introduced by the recent SA-CONTRIB-2019-035 security update (commit fbafd79a).
The query for the attachment display is missing a left join to the taxonomy term data table. As part of the security update, the code line that added the table previously was moved inside an if branch so that it will be added only if the property many_to_one_aliases of the view doesn't yet contain an alias for the field in question. Since the query for the attachment display is generated by a view that has been cloned from the original view using the clone_view() method and this property is not unset when cloning the view, it is still present from the original query building process for the parent display so adding the JOIN is skipped inadvertently.
Proposed resolution
I think the best solution for this would be to leave the security fix as is and just add the many_to_one_aliases property as an additional property to remove in clone_view(). The many_to_one_tables property is already removed there and it makes sense to do that for the aliases as well, since the query is rebuilt anyway. However, I am not entirely sure, what other consequences that might have, since I don't know the code base well enough. Hopefully a maintainer or fellow community members can add additional insight, if this is a sensible solution.
Also, there seem to be some similar, but not entirely identical issues caused by the security update, so maybe a broader approach is needed after all.
Steps to reproduce
Reduced test case:
- Install Drupal 7.x (default profile) in English.
- Install Views and Views UI 7.x-3.21/dev.
- Create one Article with tag
views. - Create a new view using the default settings. Chose any name you like.
- Add a filter for the Tags<7em> field. Make sure to check Expose this filter to visitors, to allow them to change it and Reduce duplicates.
- Add an attachment display.
- In Attachment settings > Attach to select Page.
- In Attachment settings > Inherit exposed filters select Yes.
- Save view.
- Navigate to the page of your view and select the tag views in the exposed filter. Click Apply.
Expected result
The article you created is visible two times (once shown by the page display, once shown by the attachment display).
Actual result
The article you created is visible only a single time (shown by the page display), since the JOIN to the taxonomy data table is missing from the query for the attachment display.
Attachments
- Export of the reduced test case view
- Diff of two queries for the same view from before the update and after the update to 7.x-3.21. The upper query is the query from the attachment display, the lower query is the query from the parent display. The query is a bit more complex than for the reduced test case, since I created this in a development environment of an actual site with a more complex display.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff-3040497-02-04.txt | 13.36 KB | feyp |
| #6 | views-3040497-06.patch | 14.42 KB | feyp |
| #6 | views-3040497-06-test-only.patch | 13.36 KB | feyp |
| reduced_test_view.txt | 3.96 KB | feyp | |
| query.diff | 3.51 KB | feyp |
Comments
Comment #2
feyp commentedAttached is a patch against 7.x-3.x-dev.
Comment #3
feyp commentedComment #4
jefflogan commentedI can confirm that this fixes the issues I was having with an attachment to a block.
I had slightly different filters though:
The view had the following Contextual filters:
Contextual filter "Has taxonomy term ID (with depth)"
Provide default value "Taxonomy term ID from URL"
-Load default filter from node page, that's good for related taxonomy blocks.
-Multiple-value handling, Filter to items that share any term.
Thanks for creating the patch so quickly
Comment #5
feyp commentedComment #6
feyp commentedAttached is a new patch including a test for the clone_view() method.
Comment #8
stacypendell commentedThis patch fixed the problem for my site too. Thanks FeyP.
Comment #9
brad.bulger commentedMy view has different circumstances, I think - it's the Page display of a Calendar module view - but since the upgrade one of the queries it ran was missing a relationship-based taxonomy join, not exposed, if "Reduce duplicates" was selected. By missing I mean it tried to run a query with "()" where the join should have been.
The patch fixed the problem.
Comment #10
sjerdoWorks like a charm. Code looks good. Nice! +1
Comment #11
Tilo Schumann commented#6 works for me - thank you FeyP
Comment #12
joelpittetThis fixed part of the problem for me too.
Comment #14
damienmckennaCommitted. Thanks FeyP! And thanks to everyone who reviewed the patch.