From 5e8e47d65758825afb37828c6497b4afd8f107b1 Mon Sep 17 00:00:00 2001 From: Katerina Molchanova <35141662+rokatyy@users.noreply.github.com> Date: Mon, 23 Sep 2024 12:07:59 +0300 Subject: [PATCH] Fix `QualifiedOffset.from_event` (#70) --- nuclio_sdk/qualified_offset.py | 4 +++- nuclio_sdk/test/test_qualified_offset.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nuclio_sdk/qualified_offset.py b/nuclio_sdk/qualified_offset.py index e361b4c..d6d0b86 100644 --- a/nuclio_sdk/qualified_offset.py +++ b/nuclio_sdk/qualified_offset.py @@ -21,7 +21,9 @@ def __init__(self, topic, partition, offset): @staticmethod def from_event(event): - return QualifiedOffset(event.path, event.shard_id, event.offset) + # topic resolving required to keep BC (NUC-233) + topic = event.topic if event.topic else event.path + return QualifiedOffset(topic, event.shard_id, event.offset) def compile_explicit_ack_message(self): """ diff --git a/nuclio_sdk/test/test_qualified_offset.py b/nuclio_sdk/test/test_qualified_offset.py index 3704b0d..769c45c 100644 --- a/nuclio_sdk/test/test_qualified_offset.py +++ b/nuclio_sdk/test/test_qualified_offset.py @@ -37,6 +37,13 @@ def test_compile_explicit_ack_message(self): actual_explicit_ack_message = qualified_offset.compile_explicit_ack_message() self.assertEqual(expected_explicit_ack_message, actual_explicit_ack_message) + # check that if topic is passed, it takes precedence + event.topic = "topic" + expected_explicit_ack_message["attributes"]["topic"] = "topic" + qualified_offset = nuclio_sdk.QualifiedOffset.from_event(event) + actual_explicit_ack_message = qualified_offset.compile_explicit_ack_message() + self.assertEqual(expected_explicit_ack_message, actual_explicit_ack_message) + def _check_equal_qualified_offsets(self, expected, actual): self.assertEqual(expected.topic, actual.topic) self.assertEqual(expected.partition, actual.partition)