EfficientDynamoDb
EfficientDynamoDb copied to clipboard
Error in DateTime when using BatchWrite
Hi I'm getting an exception:
"EfficientDynamoDb.Exceptions.DdbException: SerializationException
at EfficientDynamoDb.Internal.ErrorHandler.ProcessErrorAsync(DynamoDbContextMetadata metadata, HttpResponseMessage response, CancellationToken cancellationToken)
at EfficientDynamoDb.Internal.ErrorHandler.ProcessErrorAsync(DynamoDbContextMetadata metadata, HttpResponseMessage response, CancellationToken cancellationToken)
at EfficientDynamoDb.Internal.ErrorHandler.ProcessErrorAsync(DynamoDbContextMetadata metadata, HttpResponseMessage response, CancellationToken cancellationToken)
at EfficientDynamoDb.Internal.HttpApi.SendAsync(DynamoDbContextConfig config, HttpContent httpContent, CancellationToken cancellationToken)
at EfficientDynamoDb.DynamoDbContext.BatchWriteItemAsync(BuilderNode node, CancellationToken cancellationToken)
...."
when executing
await _dBContext.BatchWrite().WithItems( Batch.PutItem(batch) ).ExecuteAsync();
Where "batch" is an array of objects that includes two DateTime properties.
I couldn't figure out where the problem come from, there is possible to debug or view some logs to dig deeper?
When i tried update items one by one I got errors whe the Kind of the DateTime was Local. Now I changed all of the to UTC and works one by one, but not as a batch. I mention this because I thought at the beginig that could be related, but I´m not so sure anymore.
My previous comment here for reference:
"
I'm trying to execute
await _dBContext.PutItem() .WithItem(item) .ExecuteAsync();
And I'm getting this exception:
"EfficientDynamoDb.Exceptions.DdbException: Couldn't format DateTime ddb value from '26/04/2022 9:00:00'. at EfficientDynamoDb.Converters.DateTimeDdbConverter.Write(DdbWriter& writer, DateTime& value) at EfficientDynamoDb.Internal.Metadata.DdbPropertyInfo1.Write(Object obj, DdbWriter& ddbWriter) at EfficientDynamoDb.Internal.Extensions.DdbWriterExtensions.WriteEntityAsync(DdbWriter writer, DdbClassInfo entityClassInfo, Object entity) at EfficientDynamoDb.Internal.Operations.PutItem.PutItemHighLevelHttpContent.WriteDataAsync(DdbWriter ddbWriter) at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.SerializeToStreamAsync(Stream stream, TransportContext context) at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.SerializeToStreamAsync(Stream stream, TransportContext context) at EfficientDynamoDb.Internal.Operations.Shared.DynamoDbHttpContent.CreatePooledContentReadStreamAsync() at EfficientDynamoDb.Internal.HttpApi.SendAsync(DynamoDbContextConfig config, HttpContent httpContent, CancellationToken cancellationToken) at EfficientDynamoDb.DynamoDbContext.PutItemAsync[TEntity](BuilderNode node, CancellationToken cancellationToken) at EfficientDynamoDb.Operations.PutItem.PutItemEntityRequestBuilder1.ExecuteAsync(CancellationToken cancellationToken) ..."
the DateTime object is like this:
{26/04/2022 9:00:00} Date: {26/04/2022 0:00:00} Day: 26 DayOfWeek: Tuesday DayOfYear: 116 Hour: 9 Kind: Local Millisecond: 0 Minute: 0 Month: 4 Second: 0 Ticks: 637865604000000000 TimeOfDay: {09:00:00} Year: 2022
If a crete a new DateTime with Kind Unespecified it works fine. new DateTime(item.StartTime.Ticks, DateTimeKind.Unspecified) {26/04/2022 9:00:00} Date: {26/04/2022 0:00:00} Day: 26 DayOfWeek: Tuesday DayOfYear: 116 Hour: 9 Kind: Unspecified Millisecond: 0 Minute: 0 Month: 4 Second: 0 Ticks: 637865604000000000 TimeOfDay: {09:00:00} Year: 2022 the same if do it with UTC: {26/04/2022 9:00:00} Date: {26/04/2022 0:00:00} Day: 26 DayOfWeek: Tuesday DayOfYear: 116 Hour: 9 Kind: Utc Millisecond: 0 Minute: 0 Month: 4 Second: 0 Ticks: 637865604000000000 TimeOfDay: {09:00:00} Year: 2022 "
If a crete a new DateTime with Kind Unespecified it works fine.
new DateTime(item.StartTime.Ticks, DateTimeKind.Unspecified)
{26/04/2022 9:00:00} Date: {26/04/2022 0:00:00} Day: 26 DayOfWeek: Tuesday DayOfYear: 116 Hour: 9 Kind: Unspecified Millisecond: 0 Minute: 0 Month: 4 Second: 0 Ticks: 637865604000000000 TimeOfDay: {09:00:00} Year: 2022
the same if do it with UTC:
{26/04/2022 9:00:00}
Date: {26/04/2022 0:00:00}
Day: 26
DayOfWeek: Tuesday
DayOfYear: 116
Hour: 9
Kind: Utc
Millisecond: 0
Minute: 0
Month: 4
Second: 0
Ticks: 637865604000000000
TimeOfDay: {09:00:00}
Year: 2022
Hey @javipazos, looks like there was a default converter bug causing format exceptions while saving the local dates. I have fixed it and about to release a new stable version.
New 0.9.13 version is now available on NuGet.
Thanks for the quick response @lezzi
I've updated to 0.9.13 and I still have the same behavior. It works fine if I do it one by one, but fails when doing a batch write.
var batches = spaceConfigs.Chunk(_maxBatchOperation); foreach (var batch in batches) { //await _dBContext.BatchWrite().WithItems( // Batch.PutItem(batch) // ).ExecuteAsync(); foreach (var item in batch) { await Upsert(item); } } } public async Task Upsert(BookingTimeSlot spaceConfig) { await _dBContext.PutItem() .WithItem(spaceConfig) .ExecuteAsync(); }
Let me know if you need more details to torubleshoot
I realize I wasn't do it right. I was putting a list of items in Batch.PutItem(). I changed to do it like this and is working:
foreach (var chunk in spaceConfigs.Chunk(_maxBatchOperation)) { // Build operations var batch = new IBatchWriteBuilder[chunk.Length]; for (var i = 0; i < chunk.Length; i++) batch[i] = Batch.PutItem(chunk[i]); // Execute batch await _dBContext.BatchWrite() .WithItems(batch) .ExecuteAsync(); }
Maybe is possible to add some limitation if sending a list is a problem to avoid future errors
Closing this one as resolved.