U4-2559 - Accessing the DescendantsOrSelf() method is changing the collection scope

Created by Jeavon Leopold 29 Jul 2013, 11:58:02 Updated by Stephan 01 Nov 2013, 08:08:33

A very simple tree of: Homepage -->Page1 -->Page3 -->Page2

Test code sample checking the IsFirst and IsLast methods against the collection

@{ var subPages = Model.Content.Children;

foreach (var item in subPages)
{
   //var selectedItemState = item.DescendantsOrSelf().Any(x => x.Id == Model.Content.Id);
    
    var isLastUmb = item.IsLast();
    var isFirstUmb = item.IsFirst();

    var isLastLinq = item.Equals(subPages.Last());
    var isFirstLinq = item.Equals(subPages.First());

    var alertFirst = isFirstUmb != isFirstLinq ? " style='color:red'" : String.Empty;

    var alertLast = isLastUmb != isLastLinq ? " style='color:red'" : String.Empty;
     
    <p>@item.Name<br/>               
     <span @Html.Raw(alertFirst)>IsFirst: @isFirstUmb : @isFirstLinq</span><br/> 
     <span @Html.Raw(alertLast)>IsLast: @isLastUmb : @isLastLinq</span></p>                
}

}

This is fine and displays:

Page1 IsFirst: True : True IsLast: False : False

Page3 IsFirst: False : False IsLast: False : False

Page2 IsFirst: False : False IsLast: True : True

However now uncommment the DescendantsOrSelf() check and then this is what displays:

Page1 IsFirst: True : True IsLast: True : False

Page3 IsFirst: True : False IsLast: True : False

Page2 IsFirst: True : False IsLast: True : True

As you can see it's different and the IsFirst and IsLast helpers are returning incorrectly...

Comments

Tom Fulton 30 Jul 2013, 20:35:00

Maybe similar to U4-1842


Stephan 13 Aug 2013, 07:35:59

I haven't looked in details at that precise bug but I can confirm that in 6.x (as of today) the management of collections is somewhat buggy and IsFirst, IsLast, etc. have issues. Have it fixed, must commit the code soon as I have a bit of time.


Jeavon Leopold 13 Aug 2013, 07:42:50

Excellent, this is a really strange one as you can see just executing this method changes IsFirst on the items in the existing collection. Thanks Stephan


Jeavon Leopold 29 Aug 2013, 06:25:07

Any update on this issue Stephan?


Stephan 10 Oct 2013, 14:46:50

Fixed in 6.2.0-pubcontent branch, which should be merged soon to be part of 6.2.0. Stay tuned.


Stephan 11 Oct 2013, 10:16:57

Merged into 6.2.0, 7.0.0.


Jeavon Leopold 11 Oct 2013, 10:18:50

Awesome Stephan!


Shannon Deminick 01 Nov 2013, 06:12:50

@Stephen, is this completed? If so can you mark as fixed?


Stephan 01 Nov 2013, 08:08:24

Yup


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.3

Due in version: 7.0.0, 6.2.0

Sprint:

Story Points:

Cycle: