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

Critical DateTime to Epoch serialization issue for DynamoDb when date is beyond epoch supported date #3443

Open
sander1095 opened this issue Aug 15, 2024 · 2 comments
Labels
bug This issue is a bug. dynamodb p2 This is a standard priority issue queued

Comments

@sander1095
Copy link

sander1095 commented Aug 15, 2024

Describe the bug

There is a bug in the DynamoDB SDK when converting a DateTime to an epoch (integer). DateTime values that fall outside the supported epoch range (beyond 2038-01-19T03:14:07UTC) fail to convert to epoch and are instead sent to DynamoDB as DateTime objects. This results in inconsistent storage of DateTime values in DynamoDB.

Expected Behavior

The DateTime should always be serialized to epoch and converted back to DateTime when deserializing, regardless of the date.

This is the case when using scanamo in scala, for example, which is how I caught this!

Current Behavior

When a DateTime later than 2038-01-19T03:14:07UTC is stored, it is saved as a DateTime object instead of an epoch integer. The exception is caught and logged, but the original DateTime entry is returned without being converted to epoch.

I believe this is a critical issue, because this causes inconsistent data storage which can cause lots of issues when deserializing because the SDK most likely expects an epoch integer but receives a datetime!

Reproduction Steps

[DynamoDBTable("table")]
public class Item
{

    [DynamoDBHashKey]
    [DynamoDBProperty("id")]
    public string Id { get; set; } = null!;

    [DynamoDBProperty("date", StoreAsEpoch = true)]
    public DateTime Date { get; set; }
}

var db = app.Services.GetRequiredService<IDynamoDBContext>();
var item = new Item { Id = "1", Date = DateTime.Parse("2040-01-01T00:00:00") };
await db.SaveAsync(item);

Possible Solution

See PR #3442 for a solution and other alternatives

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.DynamoDBv2 3.7.400.2

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

@sander1095 sander1095 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2024
@sander1095 sander1095 changed the title DateTime Serialization to Epoch Fails for Dates Beyond 2038-01-19 in DynamoDB SDK Critical DateTime to Epoch serialization issue for DynamoDb when date is beyond epoch supported date Aug 15, 2024
@bhoradc bhoradc added dynamodb p2 This is a standard priority issue needs-review and removed needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2024
@bhoradc
Copy link

bhoradc commented Aug 15, 2024

Hello @sander1095,

Thank you for reporting this issue and providing your proposed solution. I will further discuss this issue with the team and we shall get back to you on the PR review.

Regards,
Chaitanya

@sander1095
Copy link
Author

Great! I just want to add 1 thing:

Another way to look at this issue:

With the code as-is, after 2038, using StoreAsEpoch will simply not do anything as it will always throw (performance hit!) and store as datetime anyway.

I believe this could be seen as a high priority issue (p1) from this angle :)

@bhoradc bhoradc added queued p1 This is a high priority issue and removed needs-review p2 This is a standard priority issue labels Aug 16, 2024
@boblodgett boblodgett added p2 This is a standard priority issue and removed p1 This is a high priority issue labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. dynamodb p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

3 participants