Skip to content

Commit

Permalink
Fix QualifiedOffset.from_event (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
rokatyy authored Sep 23, 2024
1 parent 15dd4ce commit 5e8e47d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nuclio_sdk/qualified_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
7 changes: 7 additions & 0 deletions nuclio_sdk/test/test_qualified_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5e8e47d

Please sign in to comment.