Skip to content

Commit

Permalink
Only set GSI provisioned throughput for provisioned billing modes. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinner-lyft authored and garrettheel committed Feb 9, 2022
1 parent 23eec8a commit 41bf631
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pynamodb/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pynamodb.constants import (
INCLUDE, ALL, KEYS_ONLY, ATTR_NAME, ATTR_TYPE, KEY_TYPE, KEY_SCHEMA,
ATTR_DEFINITIONS, PROJECTION_TYPE, NON_KEY_ATTRIBUTES,
PAY_PER_REQUEST_BILLING_MODE, READ_CAPACITY_UNITS, WRITE_CAPACITY_UNITS,
READ_CAPACITY_UNITS, WRITE_CAPACITY_UNITS,
)
from pynamodb.attributes import Attribute
from pynamodb.expressions.condition import Condition
Expand Down Expand Up @@ -176,11 +176,12 @@ class GlobalSecondaryIndex(Index[_M]):
@classmethod
def _get_schema(cls) -> Dict:
schema = super()._get_schema()
if getattr(cls.Meta, 'billing_mode', None) != PAY_PER_REQUEST_BILLING_MODE:
schema['provisioned_throughput'] = {
READ_CAPACITY_UNITS: cls.Meta.read_capacity_units,
WRITE_CAPACITY_UNITS: cls.Meta.write_capacity_units
}
provisioned_throughput = {}
if hasattr(cls.Meta, 'read_capacity_units'):
provisioned_throughput[READ_CAPACITY_UNITS] = cls.Meta.read_capacity_units
if hasattr(cls.Meta, 'write_capacity_units'):
provisioned_throughput[WRITE_CAPACITY_UNITS] = cls.Meta.write_capacity_units
schema['provisioned_throughput'] = provisioned_throughput
return schema


Expand Down
2 changes: 2 additions & 0 deletions pynamodb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ def _get_schema(cls) -> Dict[str, Any]:
for index in cls._indexes.values():
index_schema = index._get_schema()
if isinstance(index, GlobalSecondaryIndex):
if getattr(cls.Meta, 'billing_mode', None) == PAY_PER_REQUEST_BILLING_MODE:
index_schema.pop('provisioned_throughput', None)
schema['global_secondary_indexes'].append(index_schema)
else:
schema['local_secondary_indexes'].append(index_schema)
Expand Down

0 comments on commit 41bf631

Please sign in to comment.