Skip to content

Commit

Permalink
fix: Use built-in RecordsWithoutSchemaException (#207)
Browse files Browse the repository at this point in the history
Instead of using a generic exception and relying on an error message,
use the built-in RecordsWithoutSchemaException for when a record message
arrives before its stream's schema message.

Closes #148
  • Loading branch information
sebastianswms authored Oct 20, 2023
1 parent d674407 commit e896857
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 28 deletions.
18 changes: 0 additions & 18 deletions target_postgres/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from pathlib import PurePath

import jsonschema
from singer_sdk import typing as th
from singer_sdk.target_base import SQLTarget

Expand Down Expand Up @@ -320,20 +319,3 @@ def max_parallelism(self) -> int:
"""
# https://github.com/MeltanoLabs/target-postgres/issues/3
return 1

def _process_record_message(self, message_dict: dict) -> None:
"""Process a RECORD message.
Args:
message_dict: TODO
"""
stream_name = message_dict["stream"]
if self.mapper.stream_maps.get(stream_name) is None:
raise Exception(f"Schema message has not been sent for {stream_name}")
try:
super()._process_record_message(message_dict)
except jsonschema.exceptions.ValidationError as e:
self.logger.error(
f"Exception is being thrown for stream_name: {stream_name}"
)
raise e
10 changes: 0 additions & 10 deletions target_postgres/tests/test_standard_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ def test_aapl_to_postgres(postgres_config):
sync_end_to_end(tap, target)


def test_record_before_schema(postgres_target):
with pytest.raises(Exception) as e:
file_name = "record_before_schema.singer"
singer_file_to_target(file_name, postgres_target)

assert (
str(e.value) == "Schema message has not been sent for test_record_before_schema"
)


def test_invalid_schema(postgres_target):
with pytest.raises(Exception) as e:
file_name = "invalid_schema.singer"
Expand Down

0 comments on commit e896857

Please sign in to comment.