moto icon indicating copy to clipboard operation
moto copied to clipboard

LSI with KEYS_ONLY projection does not fetch non-projected attributes from base table (unlike real DynamoDB behavior)

Open mberthou opened this issue 7 months ago • 1 comments

LSI with KEYS_ONLY projection should automatically fetch non-projected attributes from base table. see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html#LSI.Scenario

"Every local secondary index automatically contains the partition and sort keys from its base table; you can optionally project non-key attributes into the index. When you query the index, DynamoDB can retrieve these projected attributes efficiently. When you query a local secondary index, the query can also retrieve attributes that are not projected into the index. DynamoDB automatically fetches these attributes from the base table, but at a greater latency and with higher provisioned throughput costs."

then this test is not accurate. https://github.com/getmoto/moto/blob/c04116b3556f8c5d309934ec322ca3ae93aaa34f/tests/test_dynamodb/test_dynamodb.py#L3662 query is perform without specifying select parameter of projectionexpression, so the default behavior for LSI is to fetch all attributs projected or not. It expects primary and secondary keys only and it should also contain non-projected attributs "someAttribute".

mberthou avatar May 21 '25 20:05 mberthou

Hi @mberthou, thanks for raising this!

The documentation for the SELECT-parameter has this at the end:

If neither Select nor ProjectionExpression are specified, DynamoDB defaults to ALL_ATTRIBUTES when accessing a table, and ALL_PROJECTED_ATTRIBUTES when accessing an index.

So Moto's behaviour is correct here, as far as I can tell, and when running the mentioned test (test_lsi_projection_type_keys_only) against AWS, it does pass.

I've raised #8980 to actually mark it as aws_verified, meaning it will be run against AWS on a weekly basis to ensure the tests are correct.

bblommers avatar Jun 14 '25 11:06 bblommers

I think the question is answered, so I'll close this - let us know if we've missed anything though.

bblommers avatar Aug 23 '25 18:08 bblommers