When you use the Tags property editor and leave it empty there won't be a record in the database. However, if you transfer/restore the value to another environment there will be an empty value added for the Tags property.
This can break the logic for outputting the Tags property values since a null check won't work anymore.
There was a similar issue reported on the internal tracker here for a couple of data types. That was fixed in v4.1.1
Example of the database values WorkaroundPublishing the node on the next env. will get the values in the DB in the correct state.
Rebuild the database cache and then reload memory cache will 'fix' it until the next deployment.
While we wait for a fix, rework the logic for the Tags property and use Model.HasValue(string propertyAlias)
Example
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.Root>
@using ContentModels = Umbraco.Web.PublishedModels;
@{
Layout = null;
var tagsValue = Model.HasValue("tags");
}
@if(tagsValue){
<ul>
@foreach(var tag in Model.GetProperty("tags").Value<IEnumerable<string>>()){
<li>@tag</li>
}
</ul>
}
Reproduction
If you're filing a bug, please describe how to reproduce it. Include as much
relevant information as possible, such as:
Deploy should not insert the empty values on the next environment. Might be a regression since this has not been reported before
SpecificsTested on:
Umbraco v8.18.0
Deploy v4.5.0
@if(Model.GetProperty("tags") !=null){
<ul>
@foreach(var tag in Model.GetProperty("tags").Value<IEnumerable<string>>()){
<li>@tag</li>
}
</ul>
}
That the site renders without any issues
Actual resultThere is YSOD since the null check will not work anymore since there is an empty value in the DB for the Tags property.
Stack trace
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 10: @if(Model.GetProperty("tags") !=null){
Line 11: <ul>
Line 12: @foreach(var tag in Model.GetProperty("tags").Value<IEnumerable<string>>()){
Line 13: <li>@tag</li>
Line 14: }
Source File: C:\home\site\wwwroot\Views\BrokenUsage.cshtml Line: 12
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Umbraco.Core.PropertyEditors.ValueConverters.TagsValueConverter.ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, Object source, Boolean preview) +118
Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertSourceToInter(IPublishedElement owner, Object source, Boolean preview) +91
Umbraco.Web.PublishedCache.NuCache.Property.GetInterValue(String culture, String segment) +152
Umbraco.Web.PublishedCache.NuCache.Property.GetValue(String culture, String segment) +257
Umbraco.Web.PublishedPropertyExtension.Value(IPublishedProperty property, String culture, String segment, Fallback fallback, T defaultValue) +472
ASP._Page_Views_BrokenUsage_cshtml.Execute() in C:\home\site\wwwroot\Views\BrokenUsage.cshtml:12
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +251
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +147
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +106
Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +179
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +377
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +90
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +795
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +188
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +39
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +43
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +73
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +651
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +220
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4