KenticoDevTrev / KX12To13Converter

Conversion Module to morph KX12 Portal engine sites so they can be upgraded or converted to KX13
MIT License
11 stars 1 forks source link

Ignore null values in widget properties #6

Closed roryaherne closed 1 year ago

roryaherne commented 1 year ago

In the column [CMS_Document].[DocumentPageBuilderWidgets], widgets with properties with a null value can cause parsing errors:

An unhandled exception occurred while processing the request.
InvalidCastException: Null object cannot be converted to a value type.
System.Convert.ChangeType(object value, Type conversionType, IFormatProvider provider)

JsonSerializationException: Error converting value {null} to type 'System.Int32'. Path 'editableAreas[1].sections[0].zones[0].widgets[0].variants[0].properties.SelectTopN', line 1, position 1946.
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, object value, CultureInfo culture, JsonContract contract, Type targetType)

InvalidOperationException: Incorrect format of deserialized string.
Kentico.PageBuilder.Web.Mvc.EditableAreasConfigurationSerializer.Deserialize(string json, IComponentDefinitionProvider<WidgetDefinition> widgetDefinitionProvider, IComponentDefinitionProvider<SectionDefinition> sectionDefinitionProvider, IComponentDefinitionProvider<ConditionTypeDefinition> conditionTypeDefinitionProvider)

2022-12-19 09_31_49-Window

KenticoDevTrev commented 1 year ago

@roryaherne can you tell me what you have for the Configuration of that widget?

The logic should ignore any null/whitespace value when parsing the content, but your configuration can override the value, so if you have a null in the configuration it may be killing it.

KenticoDevTrev commented 1 year ago

and by Configuration i mean the JSON structure that tells the tool how to map your widget from portal to page builder.

roryaherne commented 1 year ago

Hi Trever, here you go:

{
          "Key": "SelectTopN",
          "Value": "",
          "DefaultValue": null,
          "OutKey": "INHERIT",
          "CanContainInlineWidgets": false,
          "InlineWidgetMode": "ADDAFTER"
},

It looks like the default value was empty in kentico 12. For this instance it will make sense for me to give a default value of -1 but I can imagine other widgets whereby behaviour of the widget could vary based on a null value. But perhaps for ints that default value should be 0.

Edit: Also have the issue for a DateTime field:

{
          "Key": "StartDate",
          "Value": "",
          "DefaultValue": null,
          "OutKey": "INHERIT",
          "CanContainInlineWidgets": false,
          "InlineWidgetMode": "ADDAFTER"
},
KenticoDevTrev commented 1 year ago

It should handle this... Before I continue, can you check to make sure all the nuget packages are updated? The current logic looks fine, we have similar I think and no issue that I'm aware of, but maybe it is non string things it doesn't handle well...

roryaherne commented 1 year ago

I haven't used this since KX12To13Converter.Base v12.29.16 back in September/October so it might have been fixed since then. I'll try another import when I get the chance and keep you updated. It probably won't be until some stage in the new year though unfortunately.

Feel free to delete this in the meantime and I can recreate it if the issue persists.

KenticoDevTrev commented 1 year ago

No need to delete this, it may be an issue. Pro tip though, you can uninstall the base package and just include the actual project from this repo (update the xperience library package on it too match your project hotfix version), and you can debug it and see what may be the exact spot.

roryaherne commented 1 year ago

Hi Trevor, sorry for the late reply. I upgraded to 12.29.17 and that seems to have done the trick. Cheers, Rory