U4-9962 - Umbraco.Content(string []) return Dynamic-type change after upgrade from v7.2.8 to 7.6.1

Created by Akkawat Leelalerdwatana 29 May 2017, 04:16:07 Updated by Akkawat Leelalerdwatana 30 May 2017, 02:19:27

In V.7.2.8, When I have got node content by Umbraco.Content(string [ids]). It was return value as "Umbraco.Web.Models.DynamicPublishedContentList", no matter that ids' array is empty or it found that id in xml. So, I always check that List with "Count()" after I use that method.

But, In V.7.6.1 It's return value when is not find any xml or ids' array is empty as "Umbraco.Core.Models.IPublishedContent[]". It's array, so it can't check by "Count()".

Is there anything I do or config wrong when I upgrade version? What can I do better than find and change in my >50K line code. T^T

4 Attachments

Comments

Sebastiaan Janssen 29 May 2017, 06:05:02

As the release notes mention:

In umbracoSettings.config leave EnablePropertyValueConverters set to false - this will help your existing content queries to still work

So, in the sections/content setction, this item needs to look like: <EnablePropertyValueConverters>false</EnablePropertyValueConverters>

Make sure to read all the upgrade notes: https://our.umbraco.org/contribute/releases/761/ And follow the links to the version specific upgrade guides and the list of breaking changes.


Akkawat Leelalerdwatana 29 May 2017, 06:39:27

I already set it to "false".


Sebastiaan Janssen 29 May 2017, 07:10:02

Okay, please post your view as an example.


Akkawat Leelalerdwatana 29 May 2017, 07:34:56

Is this what you mean?

@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ string[] featureList = Model.MacroParameters["featureList"].ToString().Split(',').Take(3).ToArray(); var featureNodeList = Umbraco.Content(featureList); }

@if (featureNodeList.Count() > 0) { string featureName = ""; int index = 0;

@foreach (var featureNode in featureNodeList) { featureName = featureNode["featureName"]; if (featureNode.DocumentTypeAlias == "HotelFeatureInfo") else { index = featureName.IndexOf("#"); if (featureName.IndexOf("#") == 0) { featureName = Umbraco.Field(featureName).ToString(); if (string.IsNullOrEmpty(featureName)) {
@featureNode["featureName"]
} } } @Umbraco.RenderMacro("PRODUCTPAGE_HilightFeatureItem", new ) }
}


Sebastiaan Janssen 29 May 2017, 07:51:10

I'm afraid I can't reproduce this with either <EnablePropertyValueConverters>true</EnablePropertyValueConverters> nor <EnablePropertyValueConverters>false</EnablePropertyValueConverters>. The type is still DynamicPublishedContentList

What does your template look like, does it start with @inherits Umbraco.Web.Mvc.UmbracoTemplatePage?


Akkawat Leelalerdwatana 29 May 2017, 10:00:42

Could you please try something like this?

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @

@* the fun starts here *@

@{ var items1 = Umbraco.Content(new string[] { "5564" }); var items2 = Umbraco.Content(new string[] { "502368" }); var items3 = Umbraco.Content(new string[] { "5564", "502368" }); var items4 = Umbraco.Content(new string[] { "" }); var items5 = Umbraco.Content(new string[] { "502368", "" }); var items6 = Umbraco.Content(new string[] { "5564", "" });

@(items1.GetType())<br />
@(items2.GetType())<br />
@(items3.GetType())<br />
@(items4.GetType())<br />
@(items5.GetType())<br />
@(items6.GetType())<br />

}

I used "@inherits Umbraco.Web.Macros.PartialViewMacroPage" because it from my MacroPartialViews.


Sebastiaan Janssen 29 May 2017, 15:23:11

Ah, so it only pops up if you have empty items. Interesting.

Looks like this problem was introduced in v7.5. There's really nothing I can do for you though, if we fix this now, all other sites will start breaking who are using the updated version of this behavior.

I'm sorry that we broke this for you, but remember you're upgrading from an almost 2 year old version of Umbraco so you can expect to have to change a few things to get everything up and running again.

I think the easiest way to fix this is for you to go into all of your templates and make sure to filter out empty items. For example:

var items = new string[] { "1053", "" };
var items6 = Umbraco.Content(items.Where(x => !string.IsNullOrEmpty(x)).ToArray()); @(items6.GetType())

Or even shorter:

var items6 = Umbraco.Content(new string[] { "1053", "" }.Where(x => !string.IsNullOrEmpty(x)).ToArray()); @(items6.GetType())


Akkawat Leelalerdwatana 30 May 2017, 02:19:27

Okay thank you for your kindly help. _


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version:

Sprint:

Story Points:

Cycle: