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:

  1. Install Drupal 7.x (default profile) in English.
  2. Install Views and Views UI 7.x-3.21/dev.
  3. Create one Article with tag views.
  4. Create a new view using the default settings. Chose any name you like.
  5. 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.
  6. Add an attachment display.
  7. In Attachment settings > Attach to select Page.
  8. In Attachment settings > Inherit exposed filters select Yes.
  9. Save view.
  10. 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.

Comments

FeyP created an issue. See original summary.

feyp’s picture

Assigned: feyp » Unassigned
Issue summary: View changes
Issue tags: +Needs tests
StatusFileSize
new1.06 KB

Attached is a patch against 7.x-3.x-dev.

feyp’s picture

Status: Active » Needs review
jefflogan’s picture

I 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

feyp’s picture

feyp’s picture

Issue tags: -Needs tests
StatusFileSize
new13.36 KB
new14.42 KB
new13.36 KB

Attached is a new patch including a test for the clone_view() method.

The last submitted patch, 6: views-3040497-06-test-only.patch, failed testing. View results

stacypendell’s picture

This patch fixed the problem for my site too. Thanks FeyP.

brad.bulger’s picture

My 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.

sjerdo’s picture

Works like a charm. Code looks good. Nice! +1

Tilo Schumann’s picture

#6 works for me - thank you FeyP

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

This fixed part of the problem for me too.

Warning: Illegal offset type in isset or empty in views_many_to_one_helper->ensure_my_table() (line 1019 of /views/includes/handlers.inc).

  • DamienMcKenna committed 35bf47c on 7.x-3.x authored by FeyP
    Issue #3040497 by FeyP: [Regression] Missing JOIN in attached display...
damienmckenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks FeyP! And thanks to everyone who reviewed the patch.

Status: Fixed » Closed (fixed)

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