Skip to content

Commit

Permalink
Fix JSON serialization of timestamps in KafkaTarget (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtopper authored Dec 27, 2023
1 parent 576ffef commit 3f6e7c8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions integration/test_kafka_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
#
import asyncio
import datetime
import json
import os
from time import sleep
Expand Down Expand Up @@ -73,7 +74,7 @@ def test_kafka_target(kafka_topic_setup_teardown):
key = None
if i > 0:
key = f"key{i}"
event = Event({"hello": i}, key)
event = Event({"hello": i, "time": datetime.datetime(2023, 12, 26)}, key)
events.append(event)
controller.emit(event)

Expand All @@ -88,7 +89,7 @@ def test_kafka_target(kafka_topic_setup_teardown):
assert record.key is None
else:
assert record.key.decode("UTF-8") == event.key
assert record.value.decode("UTF-8") == json.dumps(event.body)
assert record.value.decode("UTF-8") == json.dumps(event.body, default=str)


async def async_test_write_to_kafka_full_event_readback(kafka_topic_setup_teardown):
Expand Down
2 changes: 1 addition & 1 deletion storey/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ async def _do(self, event):
record = self._event_to_writer_entry(event)
if self._full_event:
record = Event.wrap_for_serialization(event, record)
record = json.dumps(record).encode("UTF-8")
record = json.dumps(record, default=str).encode("UTF-8")
partition = None
if self._sharding_func:
sharding_func_result = self._sharding_func(event)
Expand Down

0 comments on commit 3f6e7c8

Please sign in to comment.