Techdebt: Paginator should support OrderedDict's (#6723)

This commit is contained in:
Bert Blommers 2023-08-25 08:01:25 +00:00 committed by GitHub
parent b6a582e624
commit 6eb16e8038
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -149,7 +149,7 @@ class Paginator:
token_dict["parameterChecksum"] = self._param_checksum token_dict["parameterChecksum"] = self._param_checksum
range_keys = [] range_keys = []
for attr in self._unique_attributes: for attr in self._unique_attributes:
if type(next_item) == dict: if isinstance(next_item, dict):
range_keys.append(str(next_item[attr])) range_keys.append(str(next_item[attr]))
else: else:
range_keys.append(str(getattr(next_item, attr))) range_keys.append(str(getattr(next_item, attr)))

View File

@ -1,3 +1,4 @@
from collections import OrderedDict
import unittest import unittest
import pytest import pytest
@ -38,6 +39,12 @@ def test_paginator__paginate_with_just_max_results():
assert page == results assert page == results
def test_paginator__ordered_dict():
p = Paginator(max_results=1, unique_attribute="id")
page, _ = p.paginate([OrderedDict(x) for x in results])
assert len(page) == 1
def test_paginator__paginate_without_range_key__throws_error(): def test_paginator__paginate_without_range_key__throws_error():
p = Paginator(max_results=2) p = Paginator(max_results=2)
with pytest.raises(KeyError): with pytest.raises(KeyError):