Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dzilleb5 opened this issue Feb 27, 2024 · 2 comments
Closed
Labels

Comments

@dzilleb5
Copy link

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

@AndyButland AndyButland added type/bug state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks labels Feb 28, 2024
@ronaldbarendse
Copy link

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
Copy link
Author

dzilleb5 commented Mar 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants