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(targets): Check schema has arrived before any record #1770

Merged
merged 4 commits into from
Jul 4, 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
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