dabla commented on code in PR #77423:
URL: https://github.com/apache/airflow/pull/77423#discussion_r4657424352
##########
providers/microsoft/mssql/src/airflow/providers/microsoft/mssql/hooks/mssql.py:
##########
@@ -37,6 +39,170 @@
from airflow.providers.common.sql.dialects.dialect import Dialect
from airflow.providers.openlineage.sqlparser import DatabaseInfo
+# Connection extras that are handled by the hook itself and must never reach
the DBAPI driver.
+_AIRFLOW_ONLY_EXTRAS = frozenset({"sqlalchemy_scheme", "dbapi_driver"})
+
+
+class _DbApiDriver(ABC):
+ """
+ Behaviour of ``MsSqlHook`` that depends on its ``dbapi_driver``.
+
+ The defaults are the plain DB-API behaviour, a driver only overrides what
it does differently.
+ To add a driver, subclass this and add an instance to ``_DRIVERS``.
+ """
+
+ name: str
+ default_sqlalchemy_scheme: str
+ placeholder = "%s"
+
+ @abstractmethod
+ def connect(self, connection: Connection, database: str | None) -> Any:
+ """Return a DB-API connection."""
+
+ def build_sqlalchemy_url(self, connection: Connection, database: str |
None, scheme: str) -> URL:
+ """Return the SQLAlchemy URL. Without one, the engine is built from
``MsSqlHook.get_uri()``."""
+ raise NotImplementedError
Review Comment:
**[warning]** The bare `raise NotImplementedError` drops the message
`hook.sqlalchemy_url` had with pymssql.
This is the last change I need before approving. On `main` the pymssql path
ended in `DbApiHook.sqlalchemy_url`, which raises
`NotImplementedError("'…MsSqlHook' does not implement/support built SQLAlchemy
URL.")`. Someone who reads the property directly now gets an exception without
text. A short message here is enough, for example `f"The {self.name} driver
builds no SQLAlchemy URL, use get_uri()."`.
`test_sqlalchemy_url_is_not_built_for_pymssql` only checks the type, so it
keeps passing either way.
Optional, on the two methods next to each other: a driver either builds a
URL or rewrites the URI, never both, so the default `rewrite_uri` below
(`return uri`, with `scheme` unused) is never reached: pymssql overrides it and
mssql-python never gets there. Fine to leave as the neutral default; I only
mention it so it is a choice and not an accident.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]