Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
fix: handle new relation quoting for Python introduced in dbt-1.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
chamini2 committed Mar 13, 2023
1 parent 3e95562 commit 0cfefd0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions projects/adapter/src/dbt/adapters/fal/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions projects/adapter/src/dbt/adapters/fal/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:/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)

Expand Down

0 comments on commit 0cfefd0

Please sign in to comment.