U4-6628 - AncestorOrSelf(int level) doesn't respect 'level' in some cases

Created by Tom Fulton 16 May 2015, 23:22:05 Updated by Shannon Deminick 26 Jun 2017, 07:11:21

Let's say I'm on a page at level 2 and I run this code:

var node = Model.Content.AncestorOrSelf(3);

I (think) I would expect node to be null, since "self" is level 2 and doesn't meet the level "condition".

But, it returns the current page at level 2. This is because [https://github.com/umbraco/Umbraco-CMS/blob/cd26a1ad2103b8aada7f3980028b40918daa5d05/src/Umbraco.Web/PublishedContentExtensions.cs#L1124 the code] looks for pages <= (as opposed to ==) the specified level.

In contrast, AncestorOrSelf(string nodeTypeAlias) returns null when the condition isn't met:

var node = Model.Content.AncestorOrSelf("SomeNonExistingDocType");
// node == null

Before doing a pull request I thought I'd check to see if this was expected or if I'm thinking about it incorrectly. I'm guessing it might also be considered a breaking change.

Thanks!

Comments

Shannon Deminick 26 Jun 2017, 07:11:22

Closing issue due to inactivity - see blog post for details https://umbraco.com/blog/issue-tracker-cleanup/


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.2.2, 7.2.5

Due in version:

Sprint:

Story Points:

Cycle: