From 0cfefd0af49b47d8167577f51bfd9f6d37f6abc3 Mon Sep 17 00:00:00 2001 From: Matteo Ferrando Date: Mon, 13 Mar 2023 16:59:39 -0400 Subject: [PATCH] fix: handle new relation quoting for Python introduced in dbt-1.4.5 --- .../projects/source_freshness/models/schema.yml | 2 +- projects/adapter/src/dbt/adapters/fal/impl.py | 5 ++--- projects/adapter/src/dbt/adapters/fal/wrappers.py | 2 ++ .../src/dbt/adapters/fal_experimental/adapter_support.py | 9 ++++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/projects/adapter/integration_tests/projects/source_freshness/models/schema.yml b/projects/adapter/integration_tests/projects/source_freshness/models/schema.yml index a9e4a37628..8ae98c06fd 100644 --- a/projects/adapter/integration_tests/projects/source_freshness/models/schema.yml +++ b/projects/adapter/integration_tests/projects/source_freshness/models/schema.yml @@ -8,7 +8,7 @@ sources: warn_after: { "count": 5, "period": minute } error_after: { "count": 30, "period": minute } tables: - - name: "freshness_table" + - name: freshness_table loaded_at_field: "current_timestamp" columns: - name: info diff --git a/projects/adapter/src/dbt/adapters/fal/impl.py b/projects/adapter/src/dbt/adapters/fal/impl.py index ce6f1bef64..16e14eef82 100644 --- a/projects/adapter/src/dbt/adapters/fal/impl.py +++ b/projects/adapter/src/dbt/adapters/fal/impl.py @@ -134,10 +134,9 @@ def __new__(cls, config): # TODO: maybe we can do this better? with _release_plugin_lock(): - original_plugin = FACTORY.get_plugin_by_name(fal_credentials.type) db_adapter_class = FACTORY.get_adapter_class_by_name(db_credentials.type) - - original_plugin.dependencies = [db_credentials.type] + original_plugin = FACTORY.get_plugin_by_name(fal_credentials.type) + original_plugin.dependencies = [db_credentials.type] config.python_adapter_credentials = fal_credentials config.sql_adapter_credentials = db_credentials diff --git a/projects/adapter/src/dbt/adapters/fal/wrappers.py b/projects/adapter/src/dbt/adapters/fal/wrappers.py index be8d1d5e7b..d0da9f9859 100644 --- a/projects/adapter/src/dbt/adapters/fal/wrappers.py +++ b/projects/adapter/src/dbt/adapters/fal/wrappers.py @@ -80,6 +80,8 @@ def manifest(self): return ManifestLoader.get_full_manifest(self.config) def type(self): + # NOTE: This does not let `fal__` macros to be used + # Maybe for 1.5 we will get a more reliable way to detect if we are in a SQL or Python context if find_funcs_in_stack({"render", "db_materialization"}): return self._db_adapter.type() diff --git a/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py b/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py index bf39392372..16a45342bc 100644 --- a/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py +++ b/projects/adapter/src/dbt/adapters/fal_experimental/adapter_support.py @@ -156,8 +156,15 @@ def prepare_for_adapter(adapter: BaseAdapter, function: Any) -> Any: @functools.wraps(function) def wrapped(quoted_relation: str, *args, **kwargs) -> Any: + # HACK: we need to drop the quotes from the relation parts + # This was introduced in https://github.com/dbt-labs/dbt-core/pull/7115 + # and the recommended solution would be to create a macro `fal__resolve_model_name` + # but it is not possible thanks a macro resolution error we get by returning the db_adapter type. + # The overall solution could be to avoid creating a Relation and just passing the string as is to the read/write functions. + parts = map(lambda part: part.strip('"'), [*quoted_relation.split(".")]) + relation = adapter.Relation.create( - *quoted_relation.split("."), type=RelationType.Table + *parts, type=RelationType.Table ) return function(adapter, relation, *args, **kwargs)