-
Notifications
You must be signed in to change notification settings - Fork 874
Description
Describe the bug
If you pass a DynamoDBOperationConfig in your DynamoDbOperation
new DynamoDBOperationConfig() { SkipVersionCheck = true };
While my context is configured like this:
new DynamoDBContextConfig { TableNamePrefix = $"{environment.EnvironmentName.ToLowerInvariant()}.", Conversion = DynamoDBEntryConversion.V2 };
The DynamoDbOperation will be executed using DynamoDBEntryConversion.V1 instead of the conversion specified in DynamoDBOperationConfig
Regression Issue
- Select this option if this issue appears to be a regression.
Expected Behavior
I expect that if the DynamoDBEntryConversion is not specified in the DynamoDBOperationConfig, it would fallback to DynamoDBContextConfig.Conversion.
Current Behavior
Currently if DynamoDBEntryConversion is not specified in DynamoDBOperationConfig, it default to V1 and does not check further for the DynamoDBContextConfig.
Reproduction Steps
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
class Program
{
static async Task Main(string[] args)
{
var contextConfig = new DynamoDBContextConfig() { Conversion = DynamoDBEntryConversion.V2 };
var client = new AmazonDynamoDBClient(Amazon.RegionEndpoint.EUWest1);
await client.CreateTableAsync(new CreateTableRequest(
"TestTable",
new List<KeySchemaElement>{new("PK", KeyType.HASH)},
new List<AttributeDefinition>{new("PK", ScalarAttributeType.S)},
new ProvisionedThroughput(1, 1)));
// Sleep to allow table creation
await Task.Delay(TimeSpan.FromSeconds(30));
var context = new DynamoDBContext(client, contextConfig);
// Save an item
await context.SaveAsync(new Entry { PK = "Key-1", isV2 = true });
await context.SaveAsync(new Entry { PK = "Key-2", isV2 = true }, new DynamoDBOperationConfig { SkipVersionCheck = true});
// Retrieve the item without DynamoDbOperationConfig
var table = context.GetTargetTable<Entry>();
var entry = await table.GetItemAsync(new Dictionary<string, DynamoDBEntry>{{"PK", new Primitive("Key-1")}});
var entry2 = await table.GetItemAsync(new Dictionary<string, DynamoDBEntry>{{"PK", new Primitive("Key-2")}});
CheckEntryType(entry);
CheckEntryType(entry2);
// Delete table
await client.DeleteTableAsync("TestTable");
void CheckEntryType(Document document)
{
if (document.TryGetValue("PK", out var hashKey) && document.TryGetValue("isV2", out var dbEntry) && dbEntry is DynamoDBBool)
{
Console.WriteLine($"Entry with hashkey {hashKey} is stored in V2 conversion schema");
}
else
{
Console.WriteLine($"Entry with hashkey {hashKey} is stored in V1 conversion schema");
}
}
}
}
[DynamoDBTable("TestTable")]
class Entry
{
[DynamoDBHashKey]
public string PK { get; set; }
public bool isV2 { get; set; }
}
/*
Output:
Entry with hashkey Key-1 is stored in V2 conversion schema
Entry with hashkey Key-2 is stored in V1 conversion schema
*/
Possible Solution
Make the DynamoDBEntryConversion nullable in DynamoDBOperationConfig
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
AWSSDK.DynamoDBv2 3.7.506.2
Targeted .NET Platform
.NET 8
Operating System and version
Windows 10, Ubuntu