DynamoDB: scan() should respect the Projection-attribute of GSI/LSI's (#5960)

This commit is contained in:
Bert Blommers 2023-02-22 10:16:54 -01:00 committed by GitHub
parent d1e3f50756
commit 03dfbe6931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -843,6 +843,12 @@ class Table(CloudFormationModel):
if passes_all_conditions:
results.append(item)
results = copy.deepcopy(results)
if index_name:
index = self.get_index(index_name)
for result in results:
index.project(result)
results, last_evaluated_key = self._trim_results(
results, limit, exclusive_start_key, scanned_index=index_name
)

View File

@ -4708,6 +4708,17 @@ def test_gsi_projection_type_include():
}
)
# Same when scanning the table
items = table.scan(IndexName="GSI-INC")["Items"]
items[0].should.equal(
{
"gsiK1PartitionKey": "gsi-pk",
"gsiK1SortKey": "gsi-sk",
"partitionKey": "pk-1",
"projectedAttribute": "lore ipsum",
}
)
@mock_dynamodb
def test_lsi_projection_type_keys_only():
@ -4756,6 +4767,12 @@ def test_lsi_projection_type_keys_only():
{"partitionKey": "pk-1", "sortKey": "sk-1", "lsiK1SortKey": "lsi-sk"}
)
# Same when scanning the table
items = table.scan(IndexName="LSI")["Items"]
items[0].should.equal(
{"lsiK1SortKey": "lsi-sk", "partitionKey": "pk-1", "sortKey": "sk-1"}
)
@mock_dynamodb
@pytest.mark.parametrize(