A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/umbraco/Umbraco.Deploy.Issues/issues/104 below:

Empty Tags property gets added to the database · Issue #104 · umbraco/Umbraco.Deploy.Issues · GitHub

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

Dev db:

Live db

Workaround

Publishing 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:

Bug summary

Deploy should not insert the empty values on the next environment. Might be a regression since this has not been reported before

Specifics

Tested on:
Umbraco v8.18.0
Deploy v4.5.0

Steps to reproduce
  1. Create a document type and add a Tags property editor
  2. Add logic to the template to output the Tags value. Example from the docs
@if(Model.GetProperty("tags") !=null){
    <ul>
        @foreach(var tag in Model.GetProperty("tags").Value<IEnumerable<string>>()){
            <li>@tag</li>
        }
    </ul>
}
  1. Create a node with an empty Tags value. Publish and transfer to the next environment.
  2. View Frontend on the next environment.
Expected result

That the site renders without any issues

Actual result

There 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