Repository: meltano/sdk
Pull request #2603 (2024-08-13 19:12:37)

refactor: Backwards-compatible identifier quoting in fully qualified names
Follows from #2601


<!-- readthedocs-preview meltano-sdk start -->
----
📚 Documentation preview 📚: https://meltano-sdk--2603.org.readthedocs.build/en/2603/

<!-- readthedocs-preview meltano-sdk end -->

codspeed-hq[bot]: ## [CodSpeed Performance Report](https://codspeed.io/meltano/sdk/branches/edgarrmondragon/refactor/backwards-compat-sql-ident-quoting)

### Merging #2603 will **not alter performance**

<sub>Comparing <code>edgarrmondragon/refactor/backwards-compat-sql-ident-quoting</code> (a8fcd81) with <code>main</code> (c3c2351)</sub>



### Summary

`✅ 6` untouched benchmarks





codecov[bot]: ## [Codecov](https://app.codecov.io/gh/meltano/sdk/pull/2603?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 89.61%. Comparing base [(`c3c2351`)](https://app.codecov.io/gh/meltano/sdk/commit/c3c23512aa374978d65b8d7ad8fcf6b58ccb9e7f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) to head [(`a087955`)](https://app.codecov.io/gh/meltano/sdk/commit/a0879553d2719ff2bfad3330226fa04313143540?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #2603      +/-   ##
==========================================
+ Coverage   89.57%   89.61%   +0.04%     
==========================================
  Files          58       58              
  Lines        4816     4816              
  Branches      943      944       +1     
==========================================
+ Hits         4314     4316       +2     
+ Misses        350      348       -2     
  Partials      152      152              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/meltano/sdk/pull/2603?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).


Patch:
diff --git a/singer_sdk/connectors/sql.py b/singer_sdk/connectors/sql.py
index 24f7be75..b6a74a97 100644
--- a/singer_sdk/connectors/sql.py
+++ b/singer_sdk/connectors/sql.py
@@ -52,7 +52,6 @@ class FullyQualifiedName(UserString):
         schema: str | None = None,
         database: str | None = None,
         delimiter: str = ".",
-        dialect: sa.engine.Dialect,
     ) -> None:
         """Initialize the fully qualified table name.
 
@@ -61,7 +60,6 @@ class FullyQualifiedName(UserString):
             schema: The name of the schema. Defaults to None.
             database: The name of the database. Defaults to None.
             delimiter: The delimiter to use between parts. Defaults to '.'.
-            dialect: The SQLAlchemy dialect to use for quoting.
 
         Raises:
             ValueError: If the fully qualified name could not be generated.
@@ -70,7 +68,6 @@ class FullyQualifiedName(UserString):
         self.schema = schema
         self.database = database
         self.delimiter = delimiter
-        self.dialect = dialect
 
         parts = []
         if self.database:
@@ -94,7 +91,7 @@ class FullyQualifiedName(UserString):
 
         super().__init__(self.delimiter.join(parts))
 
-    def prepare_part(self, part: str) -> str:
+    def prepare_part(self, part: str) -> str:  # noqa: PLR6301
         """Prepare a part of the fully qualified name.
 
         Args:
@@ -103,7 +100,7 @@ class FullyQualifiedName(UserString):
         Returns:
             The prepared part.
         """
-        return self.dialect.identifier_preparer.quote(part)
+        return part
 
 
 class SQLConnector:  # noqa: PLR0904
@@ -322,8 +319,8 @@ class SQLConnector:  # noqa: PLR0904
         """
         return th.to_sql_type(jsonschema_type)
 
+    @staticmethod
     def get_fully_qualified_name(
-        self,
         table_name: str | None = None,
         schema_name: str | None = None,
         db_name: str | None = None,
@@ -345,7 +342,6 @@ class SQLConnector:  # noqa: PLR0904
             schema=schema_name,
             database=db_name,
             delimiter=delimiter,
-            dialect=self._dialect,
         )
 
     @property


Test patch:
diff --git a/tests/core/test_connector_sql.py b/tests/core/test_connector_sql.py
index 6a9a5e18..c8390f33 100644
--- a/tests/core/test_connector_sql.py
+++ b/tests/core/test_connector_sql.py
@@ -360,32 +360,35 @@ def test_adapter_without_json_serde():
 
 
 def test_fully_qualified_name():
-    dialect = DefaultDialect()
-
-    fqn = FullyQualifiedName(table="my_table", dialect=dialect)
+    fqn = FullyQualifiedName(table="my_table")
     assert fqn == "my_table"
 
-    fqn = FullyQualifiedName(schema="my_schema", table="my_table", dialect=dialect)
+    fqn = FullyQualifiedName(schema="my_schema", table="my_table")
     assert fqn == "my_schema.my_table"
 
     fqn = FullyQualifiedName(
         database="my_catalog",
         schema="my_schema",
         table="my_table",
-        dialect=dialect,
     )
     assert fqn == "my_catalog.my_schema.my_table"
 
 
 def test_fully_qualified_name_with_quoting():
+    class QuotedFullyQualifiedName(FullyQualifiedName):
+        def __init__(self, *, dialect: sa.engine.Dialect, **kwargs: t.Any):
+            self.dialect = dialect
+            super().__init__(**kwargs)
+
+        def prepare_part(self, part: str) -> str:
+            return self.dialect.identifier_preparer.quote(part)
+
     dialect = DefaultDialect()
 
-    fqn = FullyQualifiedName(table="order", schema="public", dialect=dialect)
+    fqn = QuotedFullyQualifiedName(table="order", schema="public", dialect=dialect)
     assert fqn == 'public."order"'
 
 
 def test_fully_qualified_name_empty_error():
-    dialect = DefaultDialect()
-
     with pytest.raises(ValueError, match="Could not generate fully qualified name"):
-        FullyQualifiedName(dialect=dialect)
+        FullyQualifiedName()