Skip to content

Replace AttributesToGet usage with ProjectionExpression for batch get requests#4392

Open
irina-herciu wants to merge 4 commits intoaws:developmentfrom
irina-herciu:features/batchGetReplace
Open

Replace AttributesToGet usage with ProjectionExpression for batch get requests#4392
irina-herciu wants to merge 4 commits intoaws:developmentfrom
irina-herciu:features/batchGetReplace

Conversation

@irina-herciu
Copy link
Copy Markdown
Contributor

@irina-herciu irina-herciu commented Apr 20, 2026

Replace AttributesToGet usage with ProjectionExpression for batch get requests created from the DynamoDB data model layer, and add tests around DocumentBatchGet behavior.

Description

  • pass ProjectionExpression from ItemStorageConfig into DocumentBatchGet
  • build projection expressions and expression attribute names as properties are added to storage config, (AttributesToGet internal property can be removed after PR#4343 is also merged)
  • update request creation to use either ProjectionExpression or AttributesToGet, and throws if both are set,
  • add unit tests for multi-batch execution and edge cases in DocumentBatchGet.

Motivation and Context

Replace legacy params usage in HLL

Testing

Unit tests added, all existing integration tests passing

Dry-runs

  • DotNet Dry-run ID:
    • Pending
    • Completed successfully
    • Failed
  • PowerShell Dry-run ID:
    • Pending
    • Completed successfully
    • Failed

Breaking Changes Assessment

  1. Identify all breaking changes including the following details:
    • What functionality was changed?
    • How will this impact customers?
    • Why does this need to be a breaking change and what are the most notable non-breaking alternatives?
    • Are best practices being followed?
    • How have you tested this breaking change?
  2. Has a senior/+ engineer been assigned to review this PR?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@irina-herciu irina-herciu changed the title remove attribudes to get usage on batch get item Replace AttributesToGet usage with ProjectionExpression for batch get requests Apr 20, 2026
@dscpinheiro
Copy link
Copy Markdown
Contributor

Is this the same as #4343? (And if yes, should that PR be closed?)

@irina-herciu
Copy link
Copy Markdown
Contributor Author

this PR targets BatchGet operations, and #4343 is for load item operation.

there is indeed code duplication as I needed to build and pass ProjectionExpression from ItemStorageConfig

{
var projectionExpressionBuilder = new StringBuilder();
var expressionAttributeName = "#P" + ProjectionExpression.ExpressionAttributeNames.Count.ToString(CultureInfo.InvariantCulture);
if (projectionExpressionBuilder.Length == 0 && !string.IsNullOrEmpty(ProjectionExpression.ExpressionStatement))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant projectionExpressionBuilder.Length == 0 check (InternalModel.cs:688) — the StringBuilder is freshly created on line 685, so this is always true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derivedTypeAttributeName (the $type attribute used to identify which polymorphic subclass an item belongs to) is added to AttributesToGet here but not to ProjectionExpression. Since BatchGet.CreateDocumentBatch() now uses ProjectionExpression instead of AttributesToGet, and DynamoDB only returns attributes listed in the projection, the $type attribute won't come back in the response. Without it, the SDK can't tell which subclass to deserialize into and silently falls back to the base class — losing any subclass-specific properties.Fix: add AddAttributeNameToProjectionExpression(derivedTypeAttributeName); after this line. Verified with a unit test that fails on current code and passes after the fix:

[TestMethod]
public void Denormalize_DerivedTypeAttribute_MustBeInProjectionExpression()
{
var mockClient = new Mock();
var context = new DummyContext(mockClient.Object);
var config = CreatePopulatedConfig(mockClient);

var polyStorage = new StorageConfig(typeof(DerivedType));
var extraProp = new PropertyStorage(typeof(DerivedType).GetProperty(nameof(DerivedType.Extra)))
    { AttributeName = "Extra" };
extraProp.IndexNames ??= new List<string>();
extraProp.FlattenProperties ??= new List<PropertyStorage>();
polyStorage.Properties.Add(extraProp);

config.AddPolymorphicPropertyStorageConfiguration("DT1", typeof(DerivedType), polyStorage);

var polyPropOnBase = new PropertyStorage(typeof(TestClass).GetProperty(nameof(TestClass.Poly)))
    { AttributeName = "Poly", PolymorphicProperty = true };
polyPropOnBase.IndexNames ??= new List<string>();
polyPropOnBase.FlattenProperties ??= new List<PropertyStorage>();
config.BaseTypeStorageConfig.Properties.Add(polyPropOnBase);

config.Denormalize(context, derivedTypeAttributeName: "dtype");

Assert.IsTrue(config.AttributesToGet.Contains("dtype"));
Assert.IsTrue(
    config.ProjectionExpression.ExpressionAttributeNames.ContainsValue("dtype"),
    "ProjectionExpression must include the derived type attribute so polymorphic batch gets return the $type column");

}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the Denormalize, by adding missing projection attribute name. Also added integration test for BatchGet WithDerivedTypeItems as it was missing from DataModelNestedTableTests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants