[dynamodb2] Support include projection on indexes (#3498)

* [dynamodb2] Support include projection on indexes

* linter
This commit is contained in:
Garrett 2020-11-25 15:28:05 -05:00 committed by GitHub
commit 9e3b23758a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 4 deletions

View file

@ -292,11 +292,19 @@ class SecondaryIndex(BaseModel):
:return:
"""
if self.projection:
if self.projection.get("ProjectionType", None) == "KEYS_ONLY":
allowed_attributes = ",".join(
self.table_key_attrs + [key["AttributeName"] for key in self.schema]
projection_type = self.projection.get("ProjectionType", None)
key_attributes = self.table_key_attrs + [
key["AttributeName"] for key in self.schema
]
if projection_type == "KEYS_ONLY":
item.filter(",".join(key_attributes))
elif projection_type == "INCLUDE":
allowed_attributes = key_attributes + self.projection.get(
"NonKeyAttributes", []
)
item.filter(allowed_attributes)
item.filter(",".join(allowed_attributes))
# ALL is handled implicitly by not filtering
return item