umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.49k stars 2.69k forks source link

Indexing fails for date conversion #14316

Closed SATC-Ben closed 1 year ago

SATC-Ben commented 1 year ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

11.4.0

Specifics

Hi, We updated from 11.1.0 to 11.3.1 and started getting this issue when the index builds. I then saw #14096 and updated it to 11.4.0 but got the same results. For context, we use the default language (en-US) but are situated in Australia with dd/mm/yyyy formats.

[13:43:15 ERR] Error occurred executing workItem. System.InvalidOperationException: Cannot assign value "8/31/2022 12:00:00 AM" of type "System.String" to property "toDate" expecting type "System.DateTime". at Umbraco.Cms.Core.Models.Property.ThrowTypeException(Object value, Type expected, String alias) at Umbraco.Cms.Core.Models.Property.TryConvertAssignedValue(Object value, Boolean throwOnError, Object& converted) at Umbraco.Cms.Core.Models.Property.SetValue(Object value, String culture, String segment) at Umbraco.Cms.Core.PropertyEditors.NestedPropertyIndexValueFactoryBase2.GetNestedResults(String keyPrefix, String culture, String segment, Boolean published, IDictionary2 propertyTypeDictionary, TItem nestedContentRowValue, IEnumerable1 availableCultures)+MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at Umbraco.Cms.Core.PropertyEditors.NestedPropertyIndexValueFactoryBase2.Handle(TSerialized deserializedPropertyValue, IProperty property, String culture, String segment, Boolean published, IEnumerable1 availableCultures) at Umbraco.Cms.Core.PropertyEditors.JsonPropertyIndexValueFactoryBase1.GetIndexValues(IProperty property, String culture, String segment, Boolean published, IEnumerable1 availableCultures) at Umbraco.Cms.Core.PropertyEditors.NestedPropertyIndexValueFactoryBase2.GetNestedResults(String keyPrefix, String culture, String segment, Boolean published, IDictionary2 propertyTypeDictionary, TItem nestedContentRowValue, IEnumerable1 availableCultures)+MoveNext() at System.Collections.Generic.List1.InsertRange(Int32 index, IEnumerable1 collection) at Umbraco.Cms.Core.PropertyEditors.NestedPropertyIndexValueFactoryBase2.Handle(TSerialized deserializedPropertyValue, IProperty property, String culture, String segment, Boolean published, IEnumerable1 availableCultures) at Umbraco.Cms.Core.PropertyEditors.JsonPropertyIndexValueFactoryBase1.GetIndexValues(IProperty property, String culture, String segment, Boolean published, IEnumerable1 availableCultures) at Umbraco.Cms.Infrastructure.Examine.BaseValueSetBuilder1.AddPropertyValue(IProperty property, String culture, String segment, IDictionary2 values, IEnumerable1 availableCultures) at Umbraco.Cms.Infrastructure.Examine.ContentValueSetBuilder.GetValueSetsEnumerable(IContent[] content, Dictionary2 creatorIds, Dictionary2 writerIds)+MoveNext() at System.Collections.Generic.LargeArrayBuilder1.AddRange(IEnumerable1 items) at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable1 source) at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.IndexPublishedContent(Int32 contentParentId, Int32 pageIndex, Int32 pageSize, IReadOnlyList1 indexes) at Umbraco.Cms.Infrastructure.Examine.ContentIndexPopulator.PopulateIndexes(IReadOnlyList1 indexes) at Umbraco.Cms.Infrastructure.Examine.IndexPopulator.Populate(IIndex[] indexes) at Umbraco.Cms.Infrastructure.Examine.ExamineIndexRebuilder.RebuildIndex(String indexName, TimeSpan delay, CancellationToken cancellationToken) at Umbraco.Cms.Infrastructure.Examine.ExamineIndexRebuilder.<>c__DisplayClass9_1.b__1() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Umbraco.Cms.Infrastructure.HostedServices.QueuedHostedService.BackgroundProcessing(CancellationToken stoppingToken)

Steps to reproduce

Settings > Examine Management > ExternalIndex > Rebuild index

Expected result / actual result

Expected: Index runs without issue. Actual: After a while .. The process is taking longer than expected, check the Umbraco log to see if there have been any errors during this operation also the error in the log mentioned above.

github-actions[bot] commented 1 year ago

Hi there @SATC-Ben!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

elit0451 commented 1 year ago

Hi @SATC-Ben πŸ‘‹

Thanks for reaching out! To understand correctly your setup to be able to reproduce the issue, you have a Date Picker property with the alias"toDate" and can you tell me the "Date format" of the used Date Picker data type?

For example, this is the default format:

Screenshot

SATC-Ben commented 1 year ago

Hi @elit0451 ,

Thanks for the response. The date picker for the field/s that are called toDate are set to YYYY-MM-DD yes. I'm really unsure of how it's changing it to the American format along the way.

We have also just recently upgraded from V8 to V11.

The issue occurs on both Internal and External Index rebuilds.

elit0451 commented 1 year ago

After trying to hardcode the value to "8/31/2022 12:00:00 AM", it seems like the error you get is due to having the Date Picker value saved in the wrong format to the database. Can you try to save and publish your document type again and try to see if you get the same error when rebuilding the index. Hopefully saving and publishing will fix the Date Picker value format in the database.

Ahh and it is important to note that the wrong value is within a BlockList for example with a Date Picker property editor.

Let me know how it goes πŸ™‚

SATC-Ben commented 1 year ago

Right, thanks for that. I've done some digging and found the following:

So there are a few things that would be helpful to know with this:

SATC-Ben commented 1 year ago

@elit0451 Unfortunately we have the updated version with the issue on our live server which has high traffic. We also can't roll back as an error occurs due to DB structure changes made from 11.1.0 to 11.4.0 . Is someone free to respond to the above? Or can I help in any way?

elit0451 commented 1 year ago

Hi again @SATC-Ben

We are sorry to hear that you have this issue on your live server. We still need to figure out what is causing this issue, but for now, you can try to work around it by implementing the old behaviour:

https://github.com/umbraco/Umbraco-CMS/issues/14096#issuecomment-1511545767

After you've implemented it, try to rebuild the index πŸ™‚

And regarding, what has changed between version V11.1.0 to V11.3.1 that has caused the indexing system to not account for the date format that’s used in NestedContentItems? - The nested types are indexed correctly in 11.3+

SATC-Ben commented 1 year ago

Hi @elit0451, Thanks so much for the workaround and answer! Good luck with the search.

andr317c commented 1 year ago

Hey!

I just took a look at this issue, and what I can see is that you are using the default Date Picker Format which is YYYY-MM-DD, for the Australian time. But the date you are inserting into the Date Picker is in the format of MM-DD-YYYY HH:mm:ss A. The error you get is because the formats are not the same.

To fix this, I will recommend creating another DatePicker DataType which has the date format: MM-DD-YYYY HH:mm:ss A.

It's very likely that this problem was hiding there all along, however, up until 10.3 the contents of the block list and block grid were not indexed properly, so that would be why it worked before, since the data wasn't processed in the indexer.

Since there is no issue with the Date Picker, I will go ahead and close this issue. Please feel free to comment if this fix does not work! Then we can have another look πŸ˜„