From e896857258706ec964896ed9c13eb1e33956d5ef Mon Sep 17 00:00:00 2001 From: Sebastian Smiley <46581584+sebastianswms@users.noreply.github.com> Date: Fri, 20 Oct 2023 12:05:36 -0400 Subject: [PATCH] fix: Use built-in RecordsWithoutSchemaException (#207) 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 --- target_postgres/target.py | 18 ------------------ target_postgres/tests/test_standard_target.py | 10 ---------- 2 files changed, 28 deletions(-) diff --git a/target_postgres/target.py b/target_postgres/target.py index 6d21947c..3d9a5cb4 100644 --- a/target_postgres/target.py +++ b/target_postgres/target.py @@ -3,7 +3,6 @@ from pathlib import PurePath -import jsonschema from singer_sdk import typing as th from singer_sdk.target_base import SQLTarget @@ -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 diff --git a/target_postgres/tests/test_standard_target.py b/target_postgres/tests/test_standard_target.py index 421805b3..ca43f142 100644 --- a/target_postgres/tests/test_standard_target.py +++ b/target_postgres/tests/test_standard_target.py @@ -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"