Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON serialization of timestamps in KafkaTarget #483

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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