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
TransactWrite<T>.AddSaveItem throws when T does NOT contain DynamoDbProperty Attributes #3095
Comments
JCKortlang
added
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
labels
Nov 7, 2023
ashishdhingra
added
dynamodb
needs-reproduction
This issue needs reproduction.
and removed
needs-triage
This issue or PR still needs to be triaged.
labels
Nov 7, 2023
@JCKortlang Could you please share the following:
Thanks, |
ashishdhingra
added
the
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
label
Nov 8, 2023
All requested information is present in the issue? Can you please elaborate as to what is unclear? //Given
public sealed record Table1 //Same for TTable2 and TTable3
{
[DynamoDBHashKey("Id")]
public string Id { get; set; } = string.Empty;
[DynamoDBRangeKey("RelatedId")]
public string RelatedId { get; set; } = string.Empty;
}
public sealed record Table2
{
[DynamoDBHashKey("Id")]
public string Id { get; set; } = string.Empty;
[DynamoDBRangeKey("RelatedId")]
public string RelatedId { get; set; } = string.Empty;
}
//When
public static class Program
{
// "Because versioning is not supported when using batch operations, you must explicitly disable versioning"
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DotNetDynamoDBContext.BatchOperations.html
private static readonly DynamoDBOperationConfig TransactionDynamoDbOperationConfig = new()
{
SkipVersionCheck = true,
ConditionalOperator = ConditionalOperatorValues.And
};
public static Task Main(string[] args)
{
var table1 = new Table1("Id0", "Id1");
var table2 = new Table2("Id1", "Id0");
//Assuming the context has been setup correctly to map to the tables
IDynamoDbContext dbContext = new DynamoDbContext(new DynamoDbClient());
TransactWrite<Table1> t1 = dbContext.CreateTransactWrite<Table1>(TransactionDynamoDbOperationConfig);
t1.AddSaveItem(table1);
TransactWrite<Table2> t2 = dbContext.CreateTransactWrite<Table2>(TransactionDynamoDbOperationConfig);
t2.AddSaveItem(table2);
MultiTableTransactWrite transaction = dbContext.CreateMultiTableTransactWrite(t1, t2);
//Throws
await transaction.ExecuteAsync();
}
} |
github-actions
bot
removed
the
response-requested
Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
label
Nov 10, 2023
Reproducible using below code: static async Task TestTransactWrite()
{
DynamoDBOperationConfig TransactionDynamoDbOperationConfig = new()
{
SkipVersionCheck = true,
ConditionalOperator = ConditionalOperatorValues.And
};
var table1 = new Table1() { Id = "Id0", RelatedId = "Id1" };
var table2 = new Table2() { Id = "Id1", RelatedId = "Id0" };
IDynamoDBContext dbContext = new DynamoDBContext(new AmazonDynamoDBClient());
TransactWrite<Table1> t1 = dbContext.CreateTransactWrite<Table1>(TransactionDynamoDbOperationConfig);
t1.AddSaveItem(table1);
TransactWrite<Table2> t2 = dbContext.CreateTransactWrite<Table2>(TransactionDynamoDbOperationConfig);
t2.AddSaveItem(table2);
MultiTableTransactWrite transaction = dbContext.CreateMultiTableTransactWrite(t1, t2);
await transaction.ExecuteAsync();
}
[DynamoDBTable("Table1")]
public class Table1
{
[DynamoDBHashKey("Id")]
public string Id { get; set; } = string.Empty;
[DynamoDBRangeKey("RelatedId")]
public string RelatedId { get; set; } = string.Empty;
}
[DynamoDBTable("Table2")]
public class Table2
{
[DynamoDBHashKey("Id")]
public string Id { get; set; } = string.Empty;
[DynamoDBRangeKey("RelatedId")]
public string RelatedId { get; set; } = string.Empty;
} Needs review with the team. |
ashishdhingra
added
needs-review
p2
This is a standard priority issue
and removed
needs-reproduction
This issue needs reproduction.
labels
Nov 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When using
TransactWrite<T>.AddSaveItem
andT
only contains aDynamoDBHashKey
/DynamoDBRangeKey
executing the transaction results in an exception.Expected Behavior
Expect that the update / write succeeds
Current Behavior
Exception
Cause:
ToUpdateTransactWriteRequestItem.GetRequest()
removes the keys from the request which results in a null update expression per the stack traceReproduction Steps
Possible Solution
Solution: Generate update expression in ToUpdateTransactWriteRequestItem.GetRequest() when only partition and sort keys are present.
Work-Around: Add a dummy property to the model representing the table.
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
3.7.203.13
Targeted .NET Platform
.NET 7
Operating System and version
MacOS 13.6.1 (22G313)
The text was updated successfully, but these errors were encountered: