U4-9563 - GetPublishedVersion Returning Properties with Null Values

Created by Nicholas Westby 23 Feb 2017, 22:31:33 Updated by Nicholas Westby 23 Feb 2017, 23:09:09

During the Examine indexing event, I have this code:

var publishedNode = contentService.GetPublishedVersion(page.Id);

It seems to work. However, I have some code later down that attempts to get a property value, like this:

var hasLanguage = publishedNode.HasProperty("language");
var languageValue = hasLanguage
    ? publishedNode.GetValue<string>("language")
    : null;

Turns out the hasLanguage is true, but languageValue is null. Nothing strange there, except the published page does actually have a value for language. I then looked into it an it appears every property has a null value, which I tested with this code:

if(hasLanguage && languageValue == null)
{
    var allPropertyValues = publishedNode.Properties
        .Select(x => x.Alias + ": " + x.Value?.ToString())
        .ToArray();
    var breakpoint = "set breakpoint here";
}

When I inspected allPropertyValues, this is what I saw:

!nulls.png!

All the properties, including language, are null. Even though when I look at the page in the back office, there are a number of property values.

It seems like GetPublishedVersion is returning an IContent node with all null properties.

Umbraco 7.5.10.

1 Attachments

Comments

Nicholas Westby 23 Feb 2017, 22:47:03

For the heck of it, I did another test with this code in one of my CSHTML views:

var cs = ApplicationContext.Services.ContentService;
var node = cs.GetById(2286);
var properties = node.Properties.Select(x => new
{
    alias = x.Alias,
    value = x.Value == null ? "NULL" : x.Value.ToString()
}).ToArray();
var publishedNode = cs.GetPublishedVersion(node.Id);
var publishedProperties = publishedNode.Properties.Select(x => new
{
    alias = x.Alias,
    value = x.Value == null ? "NULL" : x.Value.ToString()
}).ToArray();
var debugging = "Set breakpoint here";

I then set a breakpoint to compare properties against publishedProperties. The values in properties are correct, while the values in publishedProperties are all null, so this definitely seems related to GetPublishedVersion.

Note that I am testing with a node that has an ID of 2286. For good measure, I also tested with another node (with ID 1093). The result was the same.


Nicholas Westby 23 Feb 2017, 23:09:09

This workaround seems to do the trick:

var publishedNode = contentService.GetPublishedVersion(page.Id);
publishedNode = contentService.GetByVersion(publishedNode.Version);

Definitely points to it being an issue with GetPublishedVersion.


Priority: Normal

Type: Bug

State: Submitted

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.5.10

Due in version:

Sprint:

Story Points:

Cycle: