Skip to content

Commit

Permalink
Fix: DynamoDB paginator fails when partition key is of type number
Browse files Browse the repository at this point in the history
  • Loading branch information
arunim2405 committed Jun 12, 2024
1 parent 5b71296 commit ecf8e43
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions botocore/paginate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
from itertools import tee

import jmespath

from decimal import Decimal
from botocore.exceptions import PaginationError
from botocore.utils import merge_dicts, set_value_from_jmespath

log = logging.getLogger(__name__)


class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, Decimal):
return int(o)
return json.JSONEncoder.default(o)

class TokenEncoder:
"""Encodes dictionaries into opaque strings.
Expand All @@ -49,7 +55,7 @@ def encode(self, token):
try:
# Try just using json dumps first to avoid having to traverse
# and encode the dict. In 99.9999% of cases this will work.
json_string = json.dumps(token)
json_string = json.dumps(token, cls=DecimalEncoder)
except (TypeError, UnicodeDecodeError):
# If normal dumping failed, go through and base64 encode all bytes.
encoded_token, encoded_keys = self._encode(token, [])
Expand All @@ -59,7 +65,7 @@ def encode(self, token):
encoded_token['boto_encoded_keys'] = encoded_keys

# Now that the bytes are all encoded, dump the json.
json_string = json.dumps(encoded_token)
json_string = json.dumps(encoded_token, cls=DecimalEncoder)

# base64 encode the json string to produce an opaque token string.
return base64.b64encode(json_string.encode('utf-8')).decode('utf-8')
Expand Down

0 comments on commit ecf8e43

Please sign in to comment.