Skip to content

Commit be1ba82

Browse files
authored
chore: make connection factory property with kwargs (#2544)
1 parent f645909 commit be1ba82

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sqlmesh/core/config/connection.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
import typing as t
1010
from enum import Enum
11+
from functools import partial
1112

1213
from pydantic import Field
1314
from sqlglot import exp
@@ -84,15 +85,21 @@ def is_recommended_for_state_sync(self) -> bool:
8485
"""Whether this connection is recommended for being used as a state sync for production state syncs"""
8586
return self.type_ in RECOMMENDED_STATE_SYNC_ENGINES
8687

88+
@property
89+
def _connection_factory_with_kwargs(self) -> t.Callable[[], t.Any]:
90+
"""A function that is called to return a connection object for the given Engine Adapter"""
91+
return partial(
92+
self._connection_factory,
93+
**{
94+
**self._static_connection_kwargs,
95+
**{k: v for k, v in self.dict().items() if k in self._connection_kwargs_keys},
96+
},
97+
)
98+
8799
def create_engine_adapter(self, register_comments_override: bool = False) -> EngineAdapter:
88100
"""Returns a new instance of the Engine Adapter."""
89101
return self._engine_adapter(
90-
lambda: self._connection_factory(
91-
**{
92-
**self._static_connection_kwargs,
93-
**{k: v for k, v in self.dict().items() if k in self._connection_kwargs_keys},
94-
}
95-
),
102+
self._connection_factory_with_kwargs,
96103
multithreaded=self.concurrent_tasks > 1,
97104
cursor_kwargs=self._cursor_kwargs,
98105
default_catalog=self.get_catalog(),

0 commit comments

Comments
 (0)