umbraco / Umbraco.Deploy.Issues

1 stars 0 forks source link

Data for Date Picker (Umbraco.DateTime) is transferred in the wrong format #209

Closed dzilleb5 closed 6 months ago

dzilleb5 commented 6 months ago

Hi, We have a Multilanguage Website (german, italian, english) which uses the Block Grid Editor. We have a Grid Editor which has a Block List inside. Inside the Block List we use the following Date Picker:

image

We are running in to an issue when deploying such content from one environment to another. Somehow it seems that the Date is transfered in the wrong format. Which causes the Date not the be displayed correctly in the target environment. After manually saving and publishing the node in the target environment the problem is gone and the dates can be seen in the front end.

Looking at the database we can see that the date format is different between the source and the target environment.

Format in the source database: image

Format in the target database after deploying content: image

As mentioned above after manually publishing the node in the target environment, the format of the date changes to the correct format inside the database.

Versions:

Umbraco: 12.3.3 Umbracp Deploy OnPrem: 12.1.3

ronaldbarendse commented 6 months ago

Thanks for reporting this Dennis! We've been able to replicate the issue on all latest Deploy minors and have prepared a fix for this regression.

This is caused by a change in the default value connector, which now uses the property storage type, instead of custom value prefixes to store the object type. Previously, a date/time value was stored in the Deploy artifact with the t prefix (e.g. t2024-05-15T00:00:00), but without this, Newtonsoft.Json recognizes the date/time value and automatically parses the string into a DateTime instance when deserializing the Nested Content, Block List or Block Grid JSON value. This is then converted back into a string using the default format and current culture, causing the date format to change.


As a workaround, you can change the default JSON serializer settings so dates aren't automatically parsed by adding the following code to a composer:

// Capture an existing default settings delegate
var defaultSettings = JsonConvert.DefaultSettings;
JsonConvert.DefaultSettings = () =>
{
    // Get the default settings or create a new one
    var settings = defaultSettings?.Invoke() ?? new JsonSerializerSettings();

    // Ensure that dates are not automatically parsed
    settings.DateParseHandling = DateParseHandling.None;

    return settings;
};

Do note that this might cause issues elsewhere if other code relies on the default DateParseHandling.DateTime setting. Also note that this would need to be applied to all environments.

Another workaround is to revert back to the legacy default value connector by adding builder.DeployValueConnectors().UseLegacyDefault() instead. This will prevent interoperability when using the export/import feature though, but the upside is that it will only affect Deploy...

dzilleb5 commented 6 months ago

Hi @ronaldbarendse Thanks a lot for the feedback and the possible workarounds until the next patch release. Seems to be working for us.