Skip to content

Commit

Permalink
fix: check schema has arrived before record (#1770)
Browse files Browse the repository at this point in the history
Co-authored-by: Edgar R. M <[email protected]>
  • Loading branch information
Ken Payne and edgarrmondragon authored Jul 4, 2023
1 parent d228ab0 commit efd9fb6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions singer_sdk/target_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def get_sink(
"""
_ = record # Custom implementations may use record in sink selection.
if schema is None:
self._assert_sink_exists(stream_name)
return self._sinks_active[stream_name]

existing_sink = self._sinks_active.get(stream_name, None)
Expand Down Expand Up @@ -262,7 +261,8 @@ def _assert_sink_exists(self, stream_name: str) -> None:
if not self.sink_exists(stream_name):
msg = (
f"A record for stream '{stream_name}' was encountered before a "
"corresponding schema."
"corresponding schema. Check that the Tap correctly implements "
"the Singer spec."
)
raise RecordsWithoutSchemaException(msg)

Expand Down Expand Up @@ -317,6 +317,8 @@ def _process_record_message(self, message_dict: dict) -> None:
self._assert_line_requires(message_dict, requires={"stream", "record"})

stream_name = message_dict["stream"]
self._assert_sink_exists(stream_name)

for stream_map in self.mapper.stream_maps[stream_name]:
raw_record = copy.copy(message_dict["record"])
transformed_record = stream_map.transform(raw_record)
Expand Down
6 changes: 3 additions & 3 deletions singer_sdk/testing/target_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from singer_sdk.exceptions import RecordsWithoutSchemaException

from .templates import TargetFileTestTemplate, TargetTestTemplate


Expand Down Expand Up @@ -97,9 +99,7 @@ class TargetRecordBeforeSchemaTest(TargetFileTestTemplate):

def test(self) -> None:
"""Run test."""
# TODO: the SDK should raise a better error than KeyError in this case
# https://github.com/meltano/sdk/issues/1755
with pytest.raises(KeyError):
with pytest.raises(RecordsWithoutSchemaException):
super().test()


Expand Down

0 comments on commit efd9fb6

Please sign in to comment.