diff --git a/storey/sources.py b/storey/sources.py index 4c6613d3..22f09b49 100644 --- a/storey/sources.py +++ b/storey/sources.py @@ -142,7 +142,7 @@ def _build_event(self, element, key): else: body = element - if hasattr(body, "__getitem__") and not key and self._key_field: + if isinstance(body, (dict, list)) and not key and self._key_field: if isinstance(self._key_field, str) or isinstance(self._key_field, int): key = body[self._key_field] else: diff --git a/tests/test_flow.py b/tests/test_flow.py index 80f91c77..ffb277dc 100644 --- a/tests/test_flow.py +++ b/tests/test_flow.py @@ -3425,8 +3425,8 @@ def test_key_field_and_non_dict_event_body(): ] ).run() - body1 = 1 - body2 = 2 + body1 = b"a" + body2 = b"b" controller.emit(body1) controller.emit(Event(body2, "my_key"))