From 4d2563b62ff13dc472202f6c1ef3f2f6af0809e8 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 7 Mar 2024 15:30:54 +0100 Subject: [PATCH] change resolved partial method to dedicated function --- dlt/common/configuration/__init__.py | 2 +- dlt/common/configuration/inject.py | 10 +++++++++- dlt/destinations/impl/destination/sink.py | 5 ++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dlt/common/configuration/__init__.py b/dlt/common/configuration/__init__.py index b7d868ff8b..8de57f7799 100644 --- a/dlt/common/configuration/__init__.py +++ b/dlt/common/configuration/__init__.py @@ -1,7 +1,7 @@ from .specs.base_configuration import configspec, is_valid_hint, is_secret_hint, resolve_type from .specs import known_sections from .resolve import resolve_configuration, inject_section -from .inject import with_config, last_config, get_fun_spec +from .inject import with_config, last_config, get_fun_spec, create_resolved_partial from .exceptions import ( ConfigFieldMissingException, diff --git a/dlt/common/configuration/inject.py b/dlt/common/configuration/inject.py index f80b4b092a..7e54a1bfe5 100644 --- a/dlt/common/configuration/inject.py +++ b/dlt/common/configuration/inject.py @@ -10,6 +10,7 @@ from dlt.common.configuration.resolve import resolve_configuration, inject_section from dlt.common.configuration.specs.base_configuration import BaseConfiguration from dlt.common.configuration.specs.config_section_context import ConfigSectionContext + from dlt.common.reflection.spec import spec_from_signature @@ -215,7 +216,7 @@ def _wrap(*args: Any, **kwargs: Any) -> Any: _FUNC_SPECS[id(_wrap)] = SPEC # add a method to create a pre-resolved partial - _wrap.create_resolved_partial = create_resolved_partial + _wrap.__RESOLVED_PARTIAL_FUNC__ = create_resolved_partial return _wrap # type: ignore @@ -241,3 +242,10 @@ def last_config(**kwargs: Any) -> Any: def get_orig_args(**kwargs: Any) -> Tuple[Tuple[Any], DictStrAny]: return kwargs[_ORIGINAL_ARGS] # type: ignore + + +def create_resolved_partial(f: AnyFun) -> AnyFun: + """Create a pre-resolved partial of the decorated function""" + if hasattr(f, "__RESOLVED_PARTIAL_FUNC__"): + return f.__RESOLVED_PARTIAL_FUNC__(lock=True) + return f diff --git a/dlt/destinations/impl/destination/sink.py b/dlt/destinations/impl/destination/sink.py index 6a74a577d3..84e56143ea 100644 --- a/dlt/destinations/impl/destination/sink.py +++ b/dlt/destinations/impl/destination/sink.py @@ -10,6 +10,7 @@ destination_state, commit_load_package_state, ) +from dlt.common.configuration import create_resolved_partial from dlt.common.schema import Schema, TTableSchema, TSchemaTables from dlt.common.schema.typing import TTableSchema @@ -129,9 +130,7 @@ def __init__(self, schema: Schema, config: SinkClientConfiguration) -> None: self.config: SinkClientConfiguration = config # we create pre_resolved callable here - self.destination_callable = self.config.destination_callable.create_resolved_partial( - lock=True - ) + self.destination_callable = create_resolved_partial(self.config.destination_callable) def initialize_storage(self, truncate_tables: Iterable[str] = None) -> None: pass