-
Notifications
You must be signed in to change notification settings - Fork 863
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
Fix DynamoDbv2 bug for incorrect DateTime epoch serialization when date falls out of epoch supported range #3672
Open
ashishdhingra
wants to merge
9
commits into
main-staging
Choose a base branch
from
PR-3442-DynamoDB-DateTimeEpoch
base: main-staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
44ffd82
Use Long instead of int for epoch
sander1095 914559e
Update AWSSDKUtils to return a long instead of int
sander1095 f4f5015
Use int64 -> string method and reset the code for the int method
sander1095 43ce403
Started adding the EpochLong attribute
sander1095 490b7b5
Suppress obsolete warning for succesful build
sander1095 2a12dd4
Fix formatting and throwing when data can't be (de)serialized
sander1095 f7c5e33
Remove unnecessary suppression
sander1095 9cea78b
Fixed some unhandled scenarios and updated integration tests for inco…
ashishdhingra c5b619b
Refactored code and updated test case based on review comments.
ashishdhingra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
generator/.DevConfigs/3436963d-3bfd-4d4b-a929-bc652e5c1b4d.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"core": { | ||
"changeLogMessages": [ | ||
"Added method AWSSDKUtils.ConvertFromUnixLongEpochSeconds() for converting Unix epoch seconds to DateTime structure." | ||
], | ||
"type": "patch", | ||
"updateMinimum": false | ||
}, | ||
"services": [ | ||
{ | ||
"serviceName": "DynamoDBv2", | ||
"type": "patch", | ||
"changeLogMessages": [ | ||
"Fixed an issue for incorrect DateTime epoch serialization when date falls out of epoch supported range. (Thanks @sander1095 for initial contribution)" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
|
@@ -94,6 +94,9 @@ internal class PropertyStorage : SimplePropertyStorage | |
// whether to store DateTime as epoch seconds integer | ||
public bool StoreAsEpoch { get; set; } | ||
|
||
// whether to store DateTime as epoch seconds integer (with support for dates AFTER 2038) | ||
public bool StoreAsEpochLong { get; set; } | ||
|
||
// corresponding IndexNames, if applicable | ||
public List<string> IndexNames { get; set; } | ||
|
||
|
@@ -164,15 +167,18 @@ public void Validate(DynamoDBContext context) | |
|
||
if (ConverterType != null) | ||
{ | ||
if (StoreAsEpoch) | ||
throw new InvalidOperationException("Converter for " + PropertyName + " must not be set at the same time as StoreAsEpoch is set to true"); | ||
if (StoreAsEpoch || StoreAsEpochLong) | ||
throw new InvalidOperationException("Converter for " + PropertyName + " must not be set at the same time as StoreAsEpoch or StoreAsEpochLong is set to true"); | ||
|
||
if (!Utils.CanInstantiateConverter(ConverterType) || !Utils.ImplementsInterface(ConverterType, typeof(IPropertyConverter))) | ||
throw new InvalidOperationException("Converter for " + PropertyName + " must be instantiable with no parameters and must implement IPropertyConverter"); | ||
|
||
this.Converter = Utils.InstantiateConverter(ConverterType, context) as IPropertyConverter; | ||
} | ||
|
||
if (StoreAsEpoch && StoreAsEpochLong) | ||
throw new InvalidOperationException(PropertyName + " must not set both StoreAsEpoch and StoreAsEpochLong as true at the same time."); | ||
|
||
IPropertyConverter converter; | ||
if (context.ConverterCache.TryGetValue(MemberType, out converter) && converter != null) | ||
{ | ||
|
@@ -350,6 +356,7 @@ internal class ItemStorageConfig : StorageConfig | |
public string TableName { get; set; } | ||
public bool LowerCamelCaseProperties { get; set; } | ||
public HashSet<string> AttributesToStoreAsEpoch { get; set; } | ||
public HashSet<string> AttributesToStoreAsEpochLong { get; set; } | ||
|
||
// keys | ||
public List<string> HashKeyPropertyNames { get; private set; } | ||
|
@@ -492,6 +499,8 @@ private void AddPropertyStorage(PropertyStorage value) | |
AttributesToGet.Add(attributeName); | ||
if (value.StoreAsEpoch) | ||
AttributesToStoreAsEpoch.Add(attributeName); | ||
if (value.StoreAsEpochLong) | ||
AttributesToStoreAsEpochLong.Add(attributeName); | ||
|
||
if (value.IsLSIRangeKey || value.IsGSIKey) | ||
{ | ||
|
@@ -563,6 +572,7 @@ public ItemStorageConfig(Type targetType) | |
HashKeyPropertyNames = new List<string>(); | ||
RangeKeyPropertyNames = new List<string>(); | ||
AttributesToStoreAsEpoch = new HashSet<string>(); | ||
AttributesToStoreAsEpochLong = new HashSet<string>(); | ||
} | ||
} | ||
|
||
|
@@ -730,7 +740,7 @@ private ItemStorageConfig CreateStorageConfig(Type baseType, string actualTableN | |
actualTableName = DynamoDBContext.GetTableName(config.TableName, flatConfig); | ||
} | ||
var emptyConfig = new TableConfig(actualTableName, conversion: null, consumer: Table.DynamoDBConsumer.DataModel, | ||
storeAsEpoch: null, isEmptyStringValueEnabled: false, metadataCachingMode: flatConfig.MetadataCachingMode); | ||
storeAsEpoch: null, storeAsEpochLong: null, isEmptyStringValueEnabled: false, metadataCachingMode: flatConfig.MetadataCachingMode); | ||
var table = Table.CreateTableFromItemStorageConfig(Context.Client, emptyConfig, config, flatConfig); | ||
|
||
// The table info must be cached under the actual table name exactly how it exists in the DynamoDB service. | ||
|
@@ -786,7 +796,10 @@ private static void PopulateConfigFromType(ItemStorageConfig config, Type type) | |
DynamoDBPropertyAttribute propertyAttribute = attribute as DynamoDBPropertyAttribute; | ||
if (propertyAttribute != null) | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
propertyStorage.StoreAsEpoch = propertyAttribute.StoreAsEpoch; | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
propertyStorage.StoreAsEpochLong = propertyAttribute.StoreAsEpochLong; | ||
|
||
if (propertyAttribute.Converter != null) | ||
propertyStorage.ConverterType = propertyAttribute.Converter; | ||
|
@@ -822,7 +835,7 @@ private static void PopulateConfigFromType(ItemStorageConfig config, Type type) | |
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: added whitespace? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed it somehow. |
||
config.Properties.Add(propertyStorage); | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also changed
Core
(sdk/src/Core/Amazon.Util/AWSSDKUtils.cs
) but didn't include it here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching it. Fixed. Used
updateMinimum
asfalse
since onlyAWSSDK.DynamoDBv2
uses it.