From 0fd6c1385ca67e12ef4e4e0d26f56cf7649760d0 Mon Sep 17 00:00:00 2001 From: Meder Kamalov Date: Fri, 14 Apr 2023 18:36:09 +0200 Subject: [PATCH] refact(dbt-fal): better handling of reconstructed adapter env --- projects/adapter/src/dbt/adapters/fal/impl.py | 3 ++- .../adapter/src/dbt/adapters/fal_experimental/adapter.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/adapter/src/dbt/adapters/fal/impl.py b/projects/adapter/src/dbt/adapters/fal/impl.py index 16e14eef8..ac504f022 100644 --- a/projects/adapter/src/dbt/adapters/fal/impl.py +++ b/projects/adapter/src/dbt/adapters/fal/impl.py @@ -5,6 +5,7 @@ from dbt.config.profile import Profile from dbt.adapters.base.impl import BaseAdapter, BaseRelation from dbt.adapters.factory import FACTORY +from dbt.adapters.fal_experimental.adapter import IS_RECONSTRUCTED # TODO: offer in `from isolate import is_agent` from isolate.connections.common import is_agent @@ -96,7 +97,7 @@ def load_profiles_info() -> Tuple[Profile, Dict[str, bool], Dict[str, bool]]: INHERIT_PROPERTIES = defaultdict(lambda: True) # NOTE: Should this file run on isolate agents? Could we skip it entirely and build a FalEncAdapterWrapper directly? -if not is_agent(): +if not IS_RECONSTRUCTED: DB_PROFILE, PROFILE_PROPERTIES, ARGS_PROPERTIES = load_profiles_info() DB_RELATION = FACTORY.get_relation_class_by_name(DB_PROFILE.credentials.type) diff --git a/projects/adapter/src/dbt/adapters/fal_experimental/adapter.py b/projects/adapter/src/dbt/adapters/fal_experimental/adapter.py index 36867e052..c44a90e3b 100644 --- a/projects/adapter/src/dbt/adapters/fal_experimental/adapter.py +++ b/projects/adapter/src/dbt/adapters/fal_experimental/adapter.py @@ -27,6 +27,8 @@ from .utils import extra_path, get_fal_scripts_path, retrieve_symbol +IS_RECONSTRUCTED = False + def run_with_adapter(code: str, adapter: BaseAdapter, config: RuntimeConfig) -> Any: # main symbol is defined during dbt-fal's compilation @@ -50,6 +52,10 @@ def _isolated_runner( # This function can be run in an entirely separate # process or an environment, so we need to reconstruct # the DB adapter solely from the config. + global IS_RECONSTRUCTED + IS_RECONSTRUCTED = True + from .adapter_support import reconstruct_adapter + adapter = reconstruct_adapter(config, manifest, macro_manifest) fal_scripts_path = get_fal_scripts_path(config) if local_packages is not None: