From 6eb16e8038e150a278271da190cd66fa9fd4c1ed Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 25 Aug 2023 08:01:25 +0000 Subject: [PATCH] Techdebt: Paginator should support OrderedDict's (#6723) --- moto/utilities/paginator.py | 2 +- tests/test_utilities/test_paginator.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/moto/utilities/paginator.py b/moto/utilities/paginator.py index ce411e49d..313605843 100644 --- a/moto/utilities/paginator.py +++ b/moto/utilities/paginator.py @@ -149,7 +149,7 @@ class Paginator: token_dict["parameterChecksum"] = self._param_checksum range_keys = [] for attr in self._unique_attributes: - if type(next_item) == dict: + if isinstance(next_item, dict): range_keys.append(str(next_item[attr])) else: range_keys.append(str(getattr(next_item, attr))) diff --git a/tests/test_utilities/test_paginator.py b/tests/test_utilities/test_paginator.py index 57ac62c67..5a5b5a830 100644 --- a/tests/test_utilities/test_paginator.py +++ b/tests/test_utilities/test_paginator.py @@ -1,3 +1,4 @@ +from collections import OrderedDict import unittest import pytest @@ -38,6 +39,12 @@ def test_paginator__paginate_with_just_max_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(): p = Paginator(max_results=2) with pytest.raises(KeyError):