question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error in DateTime when using BatchWrite

See original GitHub issue

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 "

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lezzicommented, Apr 27, 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.

0reactions
javipazoscommented, Apr 27, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

BatchWriteItem operation: The provided key element does ...
I am trying to write csv data from S3 to DynamoDB using AWS Lambda function. I am currently receiving the following error 'BatchWriteItem...
Read more >
BatchWriteItem - Amazon DynamoDB
The BatchWriteItem operation puts or deletes multiple items in one or more tables. A single call to BatchWriteItem can transmit up to 16MB...
Read more >
DynamoDB Batch Write, Update & Delete [How-To Guide]
View code examples and step-by-step instructions on how-to bulk delete, write and update data in DynamoDB.
Read more >
Local DynamoDB Batch Write Causes Excess SELECT ...
Hello, I have a dynamodb local instance running on my Windows 11 system and have been testing the batch write feature of DynamoDB....
Read more >
bug: 1.0.x breaks concurrent BatchWriteItem to dynamodb ...
bug : 1.0.x breaks concurrent BatchWriteItem to dynamodb tables #6682 ; aws:dynamodb AWS Dynamodb ; status: triage needed LocalStack maintainers ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found