vscode-dbt-power-user
vscode-dbt-power-user copied to clipboard
graph object not available in dbt-power-user
Expected behavior
Be able to call macro which use graph.nodes.values() method.
Actual behavior
When I use a macro which use graph context and ask to compile to dbt-power-user I have this error :
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dbt/.vscode-server/extensions/innoverio.vscode-dbt-power-user-0.47.2/dist/node_python_bridge.py", line 104, in <module>
value = eval(_compile(data['code'], '<input>', 'eval'), _locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<input>", line 1, in <module>
File "/home/dbt/.vscode-server/extensions/innoverio.vscode-dbt-power-user-0.47.2/dist/dbt_core_integration.py", line 698, in compile_sql
raise Exception(str(e))
Exception: Compilation Error in sql_operation t_3d436d9853c44498bc47853630920867 (from remote system.sql)
'dict object' has no attribute 'nodes'
> in macro doc_star (macros/doc_star.sql)
> called by sql_operation t_3d436d9853c44498bc47853630920867 (from remote system.sql)
When running dbt compile command on the same model, it works fine.
Steps To Reproduce
My goal was to generate a column list based on documentation and not on adapter.get_relation.
Add these macros to jaffle_shop project :
{%- macro doc_star(from, except=none, alias=none) -%}
{%- if execute %} {%- set node = get_node(from) %} {{- generate_star_expression(node, except or [], alias) }}
{%- else -%} {{ "*" if alias is none else alias ~ "." ~ "*" }}
{%- endif -%}
{%- endmacro %}
{%- macro get_node(model_name) -%}
{#- Filter the graph to find the node for the specified model -#}
{%- set node = (
graph.nodes.values()
| selectattr("resource_type", "equalto", "model")
| selectattr("name", "equalto", model_name.identifier)
) | first %}
{#- If node is not found in model, trying in sources -#}
{%- if node is not defined %}
{%- set node = (
graph.sources.values()
| selectattr("resource_type", "equalto", "source")
| selectattr("name", "equalto", model_name.identifier)
) | first %}
{%- if node is not defined %}
{{- exceptions.raise_compiler_error('Model or Source"' ~ model_name.identifier ~ '" is not found.') }}
{%- endif %}
{%- endif %}
{{- return(node) }}
{%- endmacro -%}
{%- macro generate_star_expression(node, except, alias) -%}
{%- set needed_columns = [] %}
{%- for column in node.columns %}
{#- Nested columns (with a '.') must be remove also #}
{%- if column not in except and '.' not in column %} {%- do needed_columns.append(column) %} {%- endif %}
{%- endfor %}
{%- if needed_columns | length == 0 %}
{{- exceptions.raise_compiler_error("Node " ~ node.unique_id ~ " has 0 column to select.") }}
{%- endif %}
{%- for column in needed_columns %}
{{- "" if alias is none else alias ~ "." }}{{- column -}}{{- ",\n" if not loop.last else "" }}
{%- endfor %}
{%- endmacro %}
Compile with dbt-power-user a new model with this code :
select {{ doc_star(ref("customers")) }} from {{ ref("customers") }}
It raises an error.
Log output/Screenshots
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/dbt/.vscode-server/extensions/innoverio.vscode-dbt-power-user-0.47.2/dist/node_python_bridge.py", line 104, in
in macro doc_star (macros/doc_star.sql) called by sql_operation t_3d436d9853c44498bc47853630920867 (from remote system.sql)
Operating System
Debian GNU/Linux
dbt version
1.8.6
dbt Adapter
bigquery
dbt Power User version
0.47.2
Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!