I tried creating multiple draggable views that include Taxonomy terms. When multiple draggable views are created, duplicate entries are shown in the results.

Steps to replicate:
1. Create 2 Taxonomy terms (Tax 1 and Tax2)
2. Create content nodes
--- 2.1 Create Video 1 - with Tax 1 & Tax2 as selected taxonomies
--- 2.2 Create Video 2 - with Tax 2 as selected taxonomy
3. Create view (T1View) that will show Tax 1 entries using DraggableViews - everything works at this point
4. Create view (T2View) that will show Tax 2 entries using DraggableViews
5. Go to the both views, change order several times and save both of them - everything breaks at this point
6. Both views (T1View & T2View) are showing Video 2 two times in the list

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

markovicyu created an issue. See original summary.

pawel_r’s picture

I have similar issue. Not using taxonomies but problem is the same. It's not 'aggregation' nor 'distinct' issue.
It's shown up suddenly after 2 months of acting properly only in view (of >20 using Views with draggable weight ordering).

EDIT:
I had to add 'relationship' to sort criteria with 'draggable views weight'. For this particular example it helped, but relationship not always can be used in given project.

markovicyu’s picture

@pawel_r - How do you add 'relationship' to sort criteria with 'draggable views weight'?

Thanks!

pawel_r’s picture

@markovicyu

Advanced -> Relationships -> add
When you have realationship you will be able to use it with sort criteria.

shaal’s picture

I have draggableviews installed on 8.2
simple team members page, one content type, no taxonomies.
it worked well, but after changing the order several times, i started seeing double content.
checking closer what's going on, i found that draggableviews weight has multiple instances for the same weight .
i couldn't 'reset' the multiple instances, and from that point on, every time i re-order the list, more duplicate weights are created.
when i uninstalled draggableviews and created the view again, it worked as it should.

unfortunately, i couldn't figure out the steps required to reproduce the bug.

would it be helpful to submit an export of that faulty view?
I would love to help getting this fixed.

harrick’s picture

@shaal

I experienced the same issue with multiple views. See my comment from in the Port to Drupal 8 issue. I attempted to fix it myself but couldn't so resorted to adding hidden date fields to determine order. Not ideal but a quick fix until this gets sorted.

webcultist’s picture

Same problem with double entries here -.-

shaal’s picture

The way I 'fixed' it, temporarily -

  • Uninstall the module (which is the only way i found to clear all its data)
  • Install the module again
  • add Draggable Views to the views that are using it

Now there are no duplicate 'weights' for the same item, so it appears as it should without duplicate entries.

frederickjh’s picture

Be careful if you use shaal's method to clear the duplicate weights. If you have views that have Draggable View displays they will be removed when you uninstall DraggableViews module. And I mean the whole View will be removed not just the Views display that is a Draggable View.

I backup my view using configuration management so I was able to restore.

I am still getting duplicates. I have two draggable Views displays in two different Views that have a piece of content that is in both. They are filtered on two different fields in their Views.

When I move the piece of content that is in both views I end up with a duplicate. I never have more than two. I think that this is because one is related to one view and the other to the other view but the draggable views filter for some reason does not filter correctly.

If I drag a piece of content that is only in one draggable View I do not get a duplicate.

frederickjh’s picture

I just realize that I had actually two pieces of content that were in both views. When I reorder only one of them I ended up with duplicates of both. So it looks like if you have content in two (and possibly more) Draggableviews displays you will end up with a duplicate for each display it is in after the first.

frederickjh’s picture

I tried reducing my Draggable View to a minimum using the instructions found here.

So, reduced the view to:

Fields:

  • Title
  • Draggable Views: Content

Filter Criteria:

  • Content: Publishing status (= Yes)
  • Content: Content type (in Basic p…)
  • Content: Spenden (= Dieser Inhalt ist MEOS "Spenden" Inhalt)

Sort Criteria:

  • Global: DraggableViews Weight (asc)

The duplicates still came after moving content in both Draggable Views where the same content was present so that the weight on the content in both views changed.

I removed the DraggableViews Weight from the View and the duplicates were gone. My analysis of this is that the DraggableViews Weight sort is not honoring the Filter Criteria but is instead looking if a draggable view weight is present in the database table and the returning the content to the view based on that.

It is like the Filter Criteria has been somehow skipped or disconnected from the output of the sort Criteria.

I did not look at the database and am assuming that there is a way to differentiate between which draggable view set the weight and which other Views displays are in the same view and using that sort filter.

This is broken. At this point for my use I do not think it is an issue as I do not expect that on the website that one piece content will be in multiple views at one time.

n3or’s picture

Status: Active » Needs review
FileSize
1.01 KB

Based on https://www.drupal.org/node/2796313 I fixed the problem by adding the view and the display name as conditions within the join.

The draggableviews_structure table may have duplicated values in entity_id, they become unique by adding a view_name and view_display condition. This condition is in the original implementation missing.

n3or’s picture

webcultist’s picture

Tried the patch and it works like a charm!!!!
Nice and thanks!!!

webcultist’s picture

Status: Needs review » Reviewed & tested by the community
Jeff Veit’s picture

I think there may be a problem with the patch in 13.

Sometimes you want the action of ordering a display to be on that display. For this use case, the patch works for me.

Other times - say when the display you are ordering is paged, or when it only shows the first few items out of hundreds, or when you want to display to the visitors in something which isn't a table (a grid perhaps) - you need one display which shows what the visitor sees, and another which lets the administrator order the items.

In the latter case, the patch breaks things. I think it's because the display names will be different - so you are ordering one display, but the order shown is built using a different display name.

From the UI point of view, I reckon the fix is to include the name of the display to be used for ordering. I see it as fitting in the Sort Criteria element for Draggable.

Jeff Veit’s picture

Status: Reviewed & tested by the community » Needs work
filburt’s picture

#16 is a good point. If you have a separate display for sorting you should not distinguish between displays, because in this case only the sorting display itself will be sorted.

In my case it was enough to remove line 14 and the View display part of line 27 at the patch in #13 and the patch works like a charm (Thanks to n3or for solving my problem after 2 days of work :-) )

Cheers,
Filburt

james.bcn’s picture

I have also had this issue - had to uninstall and reinstall the module, then reset everything back to how it was.

frederickjh’s picture

@filburt then consider submitting a patch and and interdiff.

n3or’s picture

@frederickjh: I created a patch and interdiff according to the hint of @filburt. Thanks for your help.

n3or’s picture

Status: Needs work » Needs review
brtamas’s picture

It is the same solution, but only it worked for me.

plopesc’s picture

frederickjh’s picture

The patch in #21 is working for me. Not sure why the patch in #23 needs the hook_preprocess_views_view_table() implementation. Anyone care to explain why?

thejimbirch’s picture

The patch in #23 on the latest dev solves the problem for me.

I had a single view with a Block and a Draggable view block sorting a simple content type.

I added a second view, which had a Taxonomy Term as a filter on the same content type with a block and a Draggable view block.

After saving both views had two of each result.

I updated to the latest dev, applied the patch, cleared the cache and both view now only list one result as they should.

colinlord’s picture

Just wanted to add that this patch in #23 also solves this issue for me. Thank you!

Naitschi’s picture

Hey guys,

I have the same issue mentioned in #16.

I tried all patches #21,#23 and 24# nothing worked. The sortview always shows duplicated entries and my view for showing is not sorted as the draggable weight.

I did everything that is mentioned here (latest dev version, apply patch). Also every step from the Documentation.

I'm working with drupal 8.4 maybe there is the problem?!

bailey86’s picture

https://www.drupal.org/u/seba_dru

Did you uninstall and reinstall the draggableviews module? If you didn't then the sort records might still be in the database.

stefanos.petrakis@gmail.com’s picture

Rerolling #24 against latest dev.
Additionally, providing a version of the patch for the current stable (8.x-1.0).

bisonbleu’s picture

Just ran into this issue (draggableviews duplicates), D8.5.1 (8.x-10). Patch in #30 works. Many thanks all!

frederickjh’s picture

I find it interesting that an user usability issue like this can hang around in the issue queue for over a year. It has several working patches that fix it but we still have yet to see even one comment by any one of the five maintainers of the draggableviews module.

iStryker’s picture

#1, I am pretty much the only maintainer that is active.
#2, The issue is sitting around because we want to fix it properly. The method in this issue is not the way to go. The patch is now identical as #2796313: Duplicate entities when 2 different entity types have the same entity_id the method we want to fix it as is with #2767437: Allow sort handler to select the view that stored the order

frederickjh’s picture

Thanks @iStryker!

I appreciate your work on this module and your feedback. Sorry that it seems you are shorthanded now on the project. I did not realize that there were other issues open related to this one.

Would it be a good idea to close this issue and #2796313 and ask users to add any additional feed back on #2767437?

loopy1492’s picture

I applied the 8.x-1.0.patch and it worked for me. I had to apply it manually, though, for some reason.

stefvanlooveren’s picture

#30 worked for me, thanks. Quite a big bug imo :).

alex.skrypnyk’s picture

#30 works, but be aware that it only filters by view name and not by the draggable display. This means that it will still duplicate results as many times as many displays with sorting you have.

chrisrikli’s picture

Be aware that this issue still exists in recently released versions 1.1 and 1.2; I've had to roll back to 1.0.

chrisrikli’s picture

Version: 8.x-1.0 » 8.x-1.2
Status: Needs review » Patch (to be ported)
FileSize
713 bytes

Here's a patch for 8.x-1.2. It uses identical methodology to the 8.x-1.0 patch so it will have the same issues as mentioned previously.

chrisrikli’s picture

The patch in #39 was missing some namespacing.

chrisrikli’s picture

Apologies for the run of posts, I'm having an off morning; this patch should work properly. Please delete / ignore #39/#40.

imclean’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Status: Patch (to be ported) » Needs review

Patches go against dev and there's nothing to be ported yet.

That said, as mentioned in #34, there's a more active issue: #2767437: Allow sort handler to select the view that stored the order

Maffoo’s picture

Thanks @chrisrikli, #41 worked well for me on 1.2

zanvidmar’s picture

I can also confirm that #41 works. Thank you @chrisrikli!

markdc’s picture

This issue cropped up when I added a 2nd draggable view display. Patch 41 fixes it. Thank you.

One condition: pre-patch views that were affected by this bug were still showing some (fewer) duplicate results after the patch. Duplicating the view and making sure it had a different machine name than the original solved the issue for me.

Pascal-’s picture

Ran into this problem after duplicating an existing view using draggableviews.
Patch in #41 solved it, though I had to remove my duplicate and remake it.

markdc’s picture

This works except for one caveat: when an entity shows up in 2 draggable views and you change the weight in one view, it changes the weight in the other view as well.

frederickjh’s picture

Status: Needs review » Closed (duplicate)

As @iStryker stated in his comments above in comment #33, this issue is a duplicate of #2767437: Allow sort handler to select the view that stored the order and this issue's code is taking the wrong approach to solving this and will not be committed.

#2767437: Allow sort handler to select the view that stored the order is taking the correct approach to solving this issue.

I have switched to using the patches in #2767437: Allow sort handler to select the view that stored the order and suggest others switch too to test them.

I am therefore closing this as a duplicate.

mqanneh’s picture

Patch #41 works and fixed the issue by limiting the results to the current view scope.

damondt’s picture

Before the accepted method for fixing this is completed note that this patch (#41) only adds filtering by view and not display.

joco_sp’s picture

If somebdoy will still need this. The use Drupal\views\ViewExecutable; is not needed anymore, but probably you should go and use the patch from the above mentioned duplicated issue.

joco_sp’s picture

Just a followup. We don't need the patch anymore. Tested on v2.1.1

joshuasosa’s picture

I'm currently getting duplicates due to draggableviews on 2.1.3. Patch #51 doesn't help.

Enabling "Pass Contextual Filters" helps on the display page, but still get duplicates on the ordering page.

Putting the code in from mattschaff/remove_view_duplicates.includes.php works using $row['#row']->nid but it's probably not ideal.