|
13 | 13 | from sys import version_info |
14 | 14 |
|
15 | 15 | import pydantic |
| 16 | +from pydantic import Field, computed_field |
16 | 17 | from packaging import version |
17 | | -from pydantic import Field |
18 | 18 | from pydantic_core import from_json |
19 | 19 | from sqlglot import exp |
20 | 20 | from sqlglot.errors import ParseError |
@@ -110,7 +110,14 @@ class ConnectionConfig(abc.ABC, BaseConfig): |
110 | 110 | catalog_type_overrides: t.Optional[t.Dict[str, str]] = None |
111 | 111 |
|
112 | 112 | # Whether to share a single connection across threads or create a new connection per thread. |
113 | | - shared_connection: t.ClassVar[bool] = False |
| 113 | + # |
| 114 | + # MyPy throws a "Decorators on top of @property are not supported" error despite this being a |
| 115 | + # valid decoration, and Pydantic recommend disabling the MyPy hint for this reason - see: |
| 116 | + # https://pydantic.dev/docs/validation/2.0/usage/computed_fields/ |
| 117 | + @computed_field # type: ignore[prop-decorator] |
| 118 | + @property |
| 119 | + def shared_connection(self) -> bool: |
| 120 | + return False |
114 | 121 |
|
115 | 122 | @property |
116 | 123 | @abc.abstractmethod |
@@ -311,7 +318,10 @@ class BaseDuckDBConnectionConfig(ConnectionConfig): |
311 | 318 |
|
312 | 319 | token: t.Optional[str] = None |
313 | 320 |
|
314 | | - shared_connection: t.ClassVar[bool] = True |
| 321 | + @computed_field # type: ignore[prop-decorator] |
| 322 | + @property |
| 323 | + def shared_connection(self) -> bool: |
| 324 | + return True |
315 | 325 |
|
316 | 326 | _data_file_to_adapter: t.ClassVar[t.Dict[str, EngineAdapter]] = {} |
317 | 327 |
|
@@ -820,11 +830,15 @@ class DatabricksConnectionConfig(ConnectionConfig): |
820 | 830 | DISPLAY_NAME: t.ClassVar[t.Literal["Databricks"]] = "Databricks" |
821 | 831 | DISPLAY_ORDER: t.ClassVar[t.Literal[3]] = 3 |
822 | 832 |
|
823 | | - shared_connection: t.ClassVar[bool] = True |
824 | | - |
825 | 833 | _concurrent_tasks_validator = concurrent_tasks_validator |
826 | 834 | _http_headers_validator = http_headers_validator |
827 | 835 |
|
| 836 | + @computed_field # type: ignore[prop-decorator] |
| 837 | + @property |
| 838 | + def shared_connection(self) -> bool: |
| 839 | + """The connection should only be shared if U2M OAuth is being used""" |
| 840 | + return self.auth_type is not None and self.oauth_client_secret is None |
| 841 | + |
828 | 842 | @model_validator(mode="before") |
829 | 843 | def _databricks_connect_validator(cls, data: t.Any) -> t.Any: |
830 | 844 | # SQLQueryContextLogger will output any error SQL queries even if they are in a try/except block. |
|
0 commit comments