After updating from Views 3.18 > 3.20 we noticed duplicate entries on some the previously working views.
[EDIT new finding]
I found that the issue is the taxonomy relationship (see image)
This was not causing duplicates prior to this update.
Perhaps it's the same issue as https://www.drupal.org/project/views/issues/2929804?
The only difference in query seems to be the Group By described below.
[Group by difference - old diagnosis] (I first thought this was the issue, but it seems to be related to taxonomy relationship, see above)
I noticed the difference in query was that many more fields were being added to 'Group By' on 3.20.
We have a custom code that adds nid field and a group by using query alter:
/**
* Implements hook_views_query_alter().
*/
function hook_views_query_alter(&$view, &$query) {
// On what views should we group by nid?
$group_by_views = array(
'college_program_listing',
);
// Add group by nid to the views
if (in_array($view->name, $group_by_views)) {
$query->add_field('node', 'nid', '', array('function' => 'group_by'));
$query->add_groupby('node.nid');
}
}
Result
Old query with 3.18 + this code:
GROUP BY node.nid, nid
Now with 3.20 + same code:
GROUP BY node.nid, nid, taxonomy_term_data_node.name, node.title, field_data_field_program_polaris_id.field_program_polaris_id_value
I'm assuming this is what's causing the duplicates. [Not anymore seems to be the taxonomy relationship described above]
Thanks!
Sia
Comments
Comment #2
Siavash CreditAttribution: Siavash commentedComment #3
Siavash CreditAttribution: Siavash commentedComment #4
nagy.balint CreditAttribution: nagy.balint commentedI have the same issue.
before:
GROUP BY uid, field_data_profile_firstname_user_entity_type, field_data_profile_lastname_user_entity_type, field_data_og_user_node_user_entity_type
after:
GROUP BY uid, users.uid, field_data_profile_firstname_user_entity_type, field_data_profile_firstname.profile_firstname_value, field_data_profile_lastname_user_entity_type, og_membership.created, field_data_og_user_node_user_entity_type, users.name
Comment #5
nagy.balint CreditAttribution: nagy.balint commentedComment #6
nagy.balint CreditAttribution: nagy.balint commentedI tracked this issue down to this commit: https://cgit.drupalcode.org/views/commit/?id=82987986d4ca7b4efc91ecfcbed...
Which is related to this issue #1331056: Regression: Improper use of GROUP BY statement produces ambiguous column error
It works fine just before it.
Comment #7
nagy.balint CreditAttribution: nagy.balint commentedHere is a workaround that only adds the fix from the previous issue for pgsql, while keeping the old behavior elsewhere, and so keeping backward compatibility for mysql.
This is just a quick workaround, likely a better fix can be made.
Comment #8
chrisgross CreditAttribution: chrisgross commentedI am seeing this problem, as well, only as early as 3.19. This happens even if I turn off all grouping, aggregation and exposed filters. All I did was add a criteria to sort my nodes by taxonomy term weight, and I started getting duplicates where I did not have them on 3.18. I think this issue is actually critical because it has probably broken a huge number of views. #7 does fix this for me.
Comment #9
maticb CreditAttribution: maticb commentedI can also confirm that #7 fixes the issue for me.
Comment #10
maticb CreditAttribution: maticb commentedComment #11
jonnyeom CreditAttribution: jonnyeom as a volunteer commentedThe patch fixes the issue for me as well.
Thanks!
Comment #12
DamienMcKennaCommitted. Thanks.
Comment #14
nagy.balint CreditAttribution: nagy.balint commentedHi!
Can you point me to the commit related to this task? As its not in the task, and cant find it among the commits either.
Thanks!
Comment #15
DamienMcKennaYou are correct, I made a mistake somewhere and the change didn't actually get committed. It has been committed now.