3

Resolved

bug in taxonomies when updating terms for multiple fields (with fix)

description

There's a problem in the source for updating terms. It will only show its head if you are using multiple taxonomy fields.

In the file Orchard.Taxonomies.Services.TaxonomyService, there is the following code:
var fieldIndexes = termsPart.Terms
 .Where(t => t.Field == field)
 .Select((t, i) => i)
 .OrderByDescending(i => i)
 .ToList();
The set is reduced by the where clause, so the returned indexes are incorrect.

This code needs to be changed to something like this:
var fieldIndexes = termsPart.Terms.Select((t, i) => new { Term = t, Index = i })
         .Where(x => x.Term.Field == field)
         .Select(x => x.Index)
         .OrderByDescending(i => i)
         .ToList();

comments

sebastienros wrote Nov 7, 2013 at 7:44 PM

Fixed in changeset 299e9ff946b2b35ad034e20f2528fe27fd6e9309

sebastienros wrote Nov 9, 2013 at 5:50 PM

So when you said "the code needs to be changed to something like this", it was actually a guess ;)

Jimasp wrote Nov 10, 2013 at 4:00 PM

Haha. No. You're starting to sound like Bertrand ;c)

20184 + 20204 are different issues - to me at least.

(I discovered 20204 after I had already applied the fix in 20184, so I believe both fixes are required).

Jimasp wrote Nov 10, 2013 at 4:10 PM

p.s. I realise I should have put bug recreation steps in 20204 while I could remember them. That'll teach me.(It's pretty obvious the returned indexes were wrong from just seeing the above code though).

sebastienros wrote Nov 12, 2013 at 1:08 AM

I have tried to reproduce the bugs, and was not able, even by following your repro. Tried with and without checkboxes/autocomplete. I did apply the code you provided on this thread, so I assume it's fixed now.

Jimasp wrote Nov 12, 2013 at 6:37 AM

Ok, maybe there is another fix in there somewhere that i don't have.

Which changeset did you test it with? I'd like to pull that and test it myself.

sebastienros wrote Nov 12, 2013 at 11:54 PM

latest 1.7.x

Jimasp wrote Nov 17, 2013 at 12:38 PM

Ok, I downloaded the latest 1.7.x (changeset 7dff22a47864), and extracted the zip.

I've created a video to prove beyond doubt that issue 20184 is still present (using the recreation steps previously given).

The video is here: http://content.bitsontherun.com/videos/fJyjVrEk-JJlpivC5.mp4


The confusion of the 2 bugs being related may have come from 20184 having a bad title?

Perhaps these are better titles:

20184 = the submitted state of multiple taxonomy fields is not correctly re-displayed when only one of the required fields is filled in.

20204 = multiple taxonomy fields can be incorrectly updated/stored.