Skip to content

Commit

Permalink
Extract key only if event body is a dict of a list (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtopper authored Jan 11, 2024
1 parent 5101670 commit 3d14ebd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion storey/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 3d14ebd

Please sign in to comment.