Repository: meltano/sdk
Pull request #1842 (2023-07-14 15:35:51)

fix: Ensure all expected tap parameters are passed to `SQLTap` initializer
Fixes the broken initialization of SQL taps following https://github.com/meltano/sdk/pull/1835.

The subclass initializer doesn't introduce any new arguments, so this PR changes it to use `*args` and `**kwargs` so we don't miss any changes to the parent class' initializer.

cc @BuzzCutNorman


<!-- readthedocs-preview meltano-sdk start -->
----
:books: Documentation preview :books:: https://meltano-sdk--1842.org.readthedocs.build/en/1842/

<!-- readthedocs-preview meltano-sdk end -->

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/meltano/sdk/pull/1842?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) Report
> Merging [#1842](https://app.codecov.io/gh/meltano/sdk/pull/1842?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) (7865bdd) into [main](https://app.codecov.io/gh/meltano/sdk/commit/7f33209e9a2cc8bc0166a9ecc1f7b0679e493b23?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) (7f33209) will **increase** coverage by `0.12%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main    #1842      +/-   ##
==========================================
+ Coverage   86.53%   86.65%   +0.12%     
==========================================
  Files          59       59              
  Lines        4990     4990              
  Branches      811      811              
==========================================
+ Hits         4318     4324       +6     
+ Misses        476      470       -6     
  Partials      196      196              
```


| [Impacted Files](https://app.codecov.io/gh/meltano/sdk/pull/1842?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) | Coverage Δ | |
|---|---|---|
| [singer\_sdk/tap\_base.py](https://app.codecov.io/gh/meltano/sdk/pull/1842?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano#diff-c2luZ2VyX3Nkay90YXBfYmFzZS5weQ==) | `83.48% <100.00%> (+2.67%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano)


Patch:
diff --git a/singer_sdk/tap_base.py b/singer_sdk/tap_base.py
index 95800925..08ce6f3a 100644
--- a/singer_sdk/tap_base.py
+++ b/singer_sdk/tap_base.py
@@ -612,37 +612,17 @@ class SQLTap(Tap):
     # Stream class used to initialize new SQL streams from their catalog declarations.
     default_stream_class: type[SQLStream]
 
-    def __init__(
-        self,
-        *,
-        config: dict | PurePath | str | list[PurePath | str] | None = None,
-        catalog: PurePath | str | dict | None = None,
-        state: PurePath | str | dict | None = None,
-        parse_env_config: bool = False,
-        validate_config: bool = True,
-    ) -> None:
+    def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
         """Initialize the SQL tap.
 
         The SQLTap initializer additionally creates a cache variable for _catalog_dict.
 
         Args:
-            config: Tap configuration. Can be a dictionary, a single path to a
-                configuration file, or a list of paths to multiple configuration
-                files.
-            catalog: Tap catalog. Can be a dictionary or a path to the catalog file.
-            state: Tap state. Can be dictionary or a path to the state file.
-            parse_env_config: Whether to look for configuration values in environment
-                variables.
-            validate_config: True to require validation of config settings.
+            *args: Positional arguments for the Tap initializer.
+            **kwargs: Keyword arguments for the Tap initializer.
         """
         self._catalog_dict: dict | None = None
-        super().__init__(
-            config=config,
-            catalog=catalog,
-            state=state,
-            parse_env_config=parse_env_config,
-            validate_config=validate_config,
-        )
+        super().__init__(*args, **kwargs)
 
     @property
     def catalog_dict(self) -> dict:


Test patch:
diff --git a/tests/samples/conftest.py b/tests/samples/conftest.py
index 60f27741..29560a33 100644
--- a/tests/samples/conftest.py
+++ b/tests/samples/conftest.py
@@ -73,7 +73,7 @@ def path_to_sample_data_db(tmp_path: Path) -> Path:
 
 
 @pytest.fixture
-def sqlite_sample_db_config(path_to_sample_data_db: str) -> dict:
+def sqlite_sample_db_config(path_to_sample_data_db: Path) -> dict:
     """Get configuration dictionary for target-csv."""
     return {"path_to_db": str(path_to_sample_data_db)}
 
diff --git a/tests/samples/test_tap_sqlite.py b/tests/samples/test_tap_sqlite.py
index 5e1349f9..bceaa34b 100644
--- a/tests/samples/test_tap_sqlite.py
+++ b/tests/samples/test_tap_sqlite.py
@@ -1,7 +1,11 @@
 from __future__ import annotations
 
+import json
 import typing as t
 
+from click.testing import CliRunner
+
+from samples.sample_tap_sqlite import SQLiteTap
 from samples.sample_target_csv.csv_target import SampleTargetCSV
 from singer_sdk import SQLStream
 from singer_sdk._singerlib import MetadataMapping, StreamMetadata
@@ -24,6 +28,23 @@ def _discover_and_select_all(tap: SQLTap) -> None:
         catalog_entry["metadata"] = md.to_list()
 
 
+def test_tap_sqlite_cli(sqlite_sample_db_config: dict[str, t.Any], tmp_path: Path):
+    runner = CliRunner()
+    filepath = tmp_path / "config.json"
+
+    with filepath.open("w") as f:
+        json.dump(sqlite_sample_db_config, f)
+
+    result = runner.invoke(
+        SQLiteTap.cli,
+        ["--discover", "--config", str(filepath)],
+    )
+    assert result.exit_code == 0
+
+    catalog = json.loads(result.stdout)
+    assert "streams" in catalog
+
+
 def test_sql_metadata(sqlite_sample_tap: SQLTap):
     stream = t.cast(SQLStream, sqlite_sample_tap.streams["main-t1"])
     detected_metadata = stream.catalog_entry["metadata"]