Skip to content

Commit

Permalink
Merge branch 'main' into fix/ensure-init-args-sqltap
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Jul 18, 2023
2 parents 82f8401 + e655386 commit e6e020d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This config file extends the shared Meltano GitHub org stale bot config:
# https://github.com/meltano/.github/blob/main/.github/stale.yml

_extends: .github

# In most cases, this file should not be updated.
# Updates to the stale bot config should be shared by all Meltano GitHub repositories.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ repos:
)$
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.2
rev: 0.23.3
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
rev: v0.0.278
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]
Expand Down
2 changes: 1 addition & 1 deletion docs/cli_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ plugins:
extractors:
- name: my-tap
namespace: my_tap
executable: ./my-tap.sh
executable: -e .
capabilities:
- state
- catalog
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ pytest11 = { callable = "singer_sdk:testing.pytest_plugin", extras = ["testing"]
[tool.ruff]
exclude = [
"cookiecutter/*",
"singer_sdk/helpers/_simpleeval.py",
"tests/core/test_simpleeval.py",
]
ignore = [
"ANN101", # Missing type annotation for `self` in method
Expand Down
7 changes: 5 additions & 2 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def datetime_error_treatment(self) -> DatetimeErrorTreatmentEnum:
def key_properties(self) -> list[str]:
"""Return key properties.
Override this method to return a list of key properties in a format that is
compatible with the target.
Returns:
A list of stream key properties.
"""
Expand Down Expand Up @@ -331,10 +334,10 @@ def _singer_validate_message(self, record: dict) -> None:
Raises:
MissingKeyPropertiesError: If record is missing one or more key properties.
"""
if not all(key_property in record for key_property in self.key_properties):
if any(key_property not in record for key_property in self._key_properties):
msg = (
f"Record is missing one or more key_properties. \n"
f"Key Properties: {self.key_properties}, "
f"Key Properties: {self._key_properties}, "
f"Record Keys: {list(record.keys())}"
)
raise MissingKeyPropertiesError(
Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def process_batch(self, context: dict) -> None:
self.target.records_written.extend(context["records"])
self.target.num_batches_processed += 1

@property
def key_properties(self) -> list[str]:
return [key.upper() for key in super().key_properties]


class TargetMock(Target):
"""A mock Target class."""
Expand Down
25 changes: 25 additions & 0 deletions tests/core/test_target_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import copy

import pytest

from singer_sdk.exceptions import MissingKeyPropertiesError
from tests.conftest import BatchSinkMock, TargetMock


Expand All @@ -28,3 +31,25 @@ def test_get_sink():
key_properties=key_properties,
)
assert sink_returned == sink


def test_validate_record():
target = TargetMock()
sink = BatchSinkMock(
target=target,
stream_name="test",
schema={
"properties": {
"id": {"type": ["integer"]},
"name": {"type": ["string"]},
},
},
key_properties=["id"],
)

# Test valid record
sink._singer_validate_message({"id": 1, "name": "test"})

# Test invalid record
with pytest.raises(MissingKeyPropertiesError):
sink._singer_validate_message({"name": "test"})

0 comments on commit e6e020d

Please sign in to comment.