Sometimes duplicates will appear in the view output when using views draggable. I've narrowed down the cause. It's the query. The query is not doing a WHERE draggableviews_structure.view_name = X. Since both a node and a product can have the same ID, the simple join on entity ID is not selective enough. This bug will become very apparent if you're using draggable views to order 2 types of entities on one site.

I'm going to attempt to write a patch for this, stay tuned.

Comments

terbs’s picture

StatusFileSize
new3.12 KB

Here's the attached patch file. Basically in the draggable_views_join_handler.inc file where we're getting the sort field it's like this

$view_query->view->sort['weight']->options['draggableviews_setting_view']

However, using the key "weight" is unreliable because other modules or fields might be named weight. For example, the taxonomy weight field, which is what was causing the break in my environment. I've rewritten this file to more intelligently determine exactly which field is the draggable views field instead of just relying on "weight".

ygerasimov’s picture

There was similar issue #1389440: Undefined index: draggableviews_setting_view in draggableviews_contextual_links_view_alter() (line 180 of draggableviews.module) where function draggable_views_get_draggable_sort() has been created. Possibly we can reuse it.

gumanist’s picture

@aiquandol
Could you provide step-by-step instuction to reproduce an issue?

terbs’s picture

Put a bunch of taxonomy terms and nodes in a site, then order a view by both taxonomy term weight and draggable views weight.

Since both fields are named "weight", conflicts will occur because draggable views doesn't know which "weight" field to use in the handler.

ygerasimov’s picture

I have created 4 terms. Created a view to sort terms and added in sort criteria taxonomy weight. In result I can sort terms, but no duplicates detected. If Taxonomy weight is first and then Draggableviews weight, nothing changed after I save the order and that is expected behavior.

@aiquandol could you please provide more details about settings of your view that produces duplicates? Maybe you can export it here. This might help.

terbs’s picture

StatusFileSize
new3.94 KB

Sorry if I'm being unclear. The issue can be seen most clearly in the code itself. This is in draggable_views_join_handler.inc

  $view_query->view->sort['weight']->options['draggableviews_setting_view']

Lines like this, where we're selecting a member of the $view_query->view->sort array using the key ['weight'], is where the problem lies. ['weight'] is a vague selector that can match multiple sort criteria, not just the draggable views weight sort. If you add "Taxonomy: Weight" to your sort criteria first, then "Taxonomy: Weight" gets the ['weight'] key in the sort array and draggable views gets the key ['weight_1'].

It's the fact that we're using the vague selector ['weight'] to determine which field is the draggable field that causes a lot of errors like duplicates.

Attached is a view for reference. Import it, then put a dsm() or some kind of variable dump in draggable_views_join_handler.inc right above line 31

      dsm($view_query->view->sort);
      if (!empty($view_query->view->sort['weight']->options['draggableviews_setting_view'])) {

You'll see in the variable dump that the draggable views handler has the key ['weight_1'] but the if statement is using the key ['weight'] (which is the taxonomy weight sort), which is causing the view to bug out and fail in weird ways (one of which is creating duplicates).

The solution proposed in the patch is to find the draggable sort field's key in a more robust way instead of just $view_query->view->sort['weight'] (which will fail).

ygerasimov’s picture

Status: Active » Needs review
StatusFileSize
new2.7 KB

Yes, now I finally got duplicates locally! @aiquandol, thanks for your patience. Please test attached patch that fixes pointed issue.

ygerasimov’s picture

Status: Needs review » Fixed

Comitted.

Status: Fixed » Closed (fixed)

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

fernly’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

I can confirm this issue is still occurring using the dev version of 2013-Sep-30.

Context:
A view is displaying product display nodes and contains filters and other sort criteria in an exposed filter block. This is the front-end display. After saving the custom order using the drag functionality in a second views display (back-end), duplicates start popping up in the original front-end display. Distinct doesn't work here.

fernly’s picture

Status: Active » Closed (fixed)

Apparently it's another issue. I take it back :-)

pedromvpg’s picture

It looks like this is still happening on 7.x-2.x-dev (2014-Dec-05). It works fine the first time but after a couple of saves I have 5 different instances of the same node on the draggable view page. All of the above patches are rejected in this version.

Anyone else having this problem?
Anyone know of any alternatives? Using earlier versions of the module create an "Illegal Choice" problem as seen here https://www.drupal.org/node/1537532.

pedromvpg’s picture

Status: Closed (fixed) » Needs work

Still occurring in version 7.x-2.x-dev (2014-Dec-05).

istryker’s picture

Title: Sorting by a draggable view sometimes causes duplicates to appear in output views » Sorting by a draggable view causes duplicates if multiple sorts are called 'weight'
Status: Needs work » Closed (fixed)

Changing the title marking it as fixed. We cannot have multiple issue (that are similar) in the same issue. It gets confusing. @pedromvpg open another issue if you are still having problem and add this issue as a related issue.