AltimateAI / vscode-dbt-power-user

This extension makes vscode seamlessly work with dbt™: Auto-complete, preview, column lineage, AI docs generation, health checks, cost estimation etc
https://www.altimate.ai
MIT License
427 stars 84 forks source link

Compiled dbt Preview button not working #1226

Open mdesmet opened 1 week ago

mdesmet commented 1 week ago

Discussed in https://github.com/AltimateAI/vscode-dbt-power-user/discussions/1225

Originally posted by **letuio** June 18, 2024 Hi everyone, I was looking for some help, since this option was working fine for me until yesterday afternoon. It was fine in the morning and for the life of me I can't figure out why it stopped in the middle of the day, as far as I know there shouldn't have been any changes. The problem is the following, the button to see the compiled dbt preview stopped working and it is giving me the following issue, no matter the model that I am using. For example: ![image](https://github.com/AltimateAI/vscode-dbt-power-user/assets/152965967/a0232c27-f82b-4a5e-b263-b701c88c38cf) It always seems to be the same problem, no matter the model. I am not sure what changed, but I've been using it for quite a while with no issues. I am able to run models and compile models using the right click menu or through the CLI, I can see the compiled code on the target folder. But this specific button is not working. Seems to indicate that it expects a 'NodeInfo' object to have the 'keys' attribute, but I don't know anything about that. Any help would be appreciated, as I like this feature a lot and I use it constantly. Only work-around I've seen is to compile the code manually and then use the command to "open dbt target folder compiled" but that is hardly as convenient. Thanks in advance.
EFox2413 commented 1 week ago

+1

Getting the same issue when trying to preview compiled SQL via ctrl+enter. Running dbt models and building works as expected, but executing SQL previews gives the no keys attribute error on the NodeInfo object.

Downgrading to v0.39.20 fixes the issue as the previous version doesn't have this problem. FYI @mdesmet

davidwitk commented 1 week ago

+1

We face a similar issue on >=0.40.

Running with dbt=1.8.2
dbt version: 1.8.2
python version: 3.8.18

Additional info: We use it (sometimes) in combination with the upstream_prod package, which overrides the ref macro https://github.com/LewisDavies/upstream-prod

Exception: Compilation Error in sql_operation t_04688e1e7d094694bd6db7270f80272d (from remote system.sql)
  'dict object' has no attribute 'nodes'

  > in macro find_model_node (macros/upstream_prod/find_model_node.sql)
  > called by macro default__ref (../utils/macros/global/ref.sql)
  > called by macro ref (../utils/macros/global/ref.sql)
  > called by sql_operation t_04688e1e7d094694bd6db7270f80272d (from remote system.sql)

Downgrading to v0.39.20 fixes the issue.

anandgupta42 commented 1 week ago

@davidwitk @EFox2413 Can you please upgrade to version 0.40.2 and let us know if the issue has been fixed? Also, we no longer support version < 1.6, so please consider updating your dbt version.

davidwitk commented 1 week ago

@anandgupta42 I tried 0.40.2 and 0.40.3, but still the same error

romiof commented 1 week ago

Same issue here !

@anandgupta42 version 0.40.3 fix preview query execution (Ctrl + Enter)... but Compiled dbt Preview (Ctrl + ~) stills broken.

Downgrade to 0.39.20 fixes both.

mdesmet commented 1 week ago

@davidwitk : Can you provide the full stack trace?

davidwitk commented 5 days ago

@mdesmet Here you go, on 0.40.3:

Traceback (most recent call last):
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 326, in exception_handler
    yield
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 298, in call_macro
    return macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 768, in __call__
    return self._invoke(arguments, autoescape)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 51, in macro
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/sandbox.py", line 327, in getattr
    value = getattr(obj, attribute)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 864, in __getattr__
    return self._fail_with_undefined_error()
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 857, in _fail_with_undefined_error
    raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'nodes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 713, in _compile_node
    compiled_node = self.sql_compiler.compile(self.dbt)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/task/sql.py", line 44, in compile
    return self.compiler.compile_node(self.node, manifest, {}, write=False)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/compilation.py", line 533, in compile_node
    node = self._compile_code(node, manifest, extra_context)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/compilation.py", line 421, in _compile_code
    node.compiled_code = jinja.get_rendered(
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/clients/jinja.py", line 146, in get_rendered
    rendered = render_template(template, ctx, node)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 539, in render_template
    return template.render(ctx)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 144, in render
    return self.environment.handle_exception()
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 19, in top-level template code
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/sandbox.py", line 394, in call
    return __context.call(__obj, *args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/clients/jinja.py", line 84, in __call__
    return self.call_macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 298, in call_macro
    return macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 12, in template
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/sandbox.py", line 394, in call
    return __context.call(__obj, *args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/clients/jinja.py", line 84, in __call__
    return self.call_macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 298, in call_macro
    return macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 30, in template
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/sandbox.py", line 394, in call
    return __context.call(__obj, *args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/clients/jinja.py", line 84, in __call__
    return self.call_macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 298, in call_macro
    return macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/runtime.py", line 782, in _invoke
    rv = self._func(*arguments)
  File "<template>", line 2, in template
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/jinja2/sandbox.py", line 394, in call
    return __context.call(__obj, *args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt/clients/jinja.py", line 84, in __call__
    return self.call_macro(*args, **kwargs)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 300, in call_macro
    return e.value
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/Users/davidwitkowski/.pyenv/versions/3.8.18/envs/dbt-bbc/lib/python3.8/site-packages/dbt_common/clients/jinja.py", line 328, in exception_handler
    raise CaughtMacroErrorWithNodeError(exc=e, node=self.macro)
dbt_common.exceptions.macros.CaughtMacroErrorWithNodeError: Compilation Error in sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)
  'dict object' has no attribute 'nodes'

  > in macro find_model_node (macros/upstream_prod/find_model_node.sql)
  > called by macro default__ref (../utils/macros/global/ref.sql)
  > called by macro ref (../utils/macros/global/ref.sql)
  > called by sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 693, in _compile_sql
    node = self._compile_node(server_node)
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 720, in _compile_node
    raise Exception(str(e))
Exception: Compilation Error in sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)
  'dict object' has no attribute 'nodes'

  > in macro find_model_node (macros/upstream_prod/find_model_node.sql)
  > called by macro default__ref (../utils/macros/global/ref.sql)
  > called by macro ref (../utils/macros/global/ref.sql)
  > called by sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 675, in compile_sql
    return self._compile_sql(raw_sql, original_node)
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 697, in _compile_sql
    raise Exception(str(e))
Exception: Compilation Error in sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)
  'dict object' has no attribute 'nodes'

  > in macro find_model_node (macros/upstream_prod/find_model_node.sql)
  > called by macro default__ref (../utils/macros/global/ref.sql)
  > called by macro ref (../utils/macros/global/ref.sql)
  > called by sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/node_python_bridge.py", line 104, in <module>
    value = eval(_compile(data['code'], '<input>', 'eval'), _locals)
  File "<input>", line 1, in <module>
  File "/Users/davidwitkowski/.vscode/extensions/innoverio.vscode-dbt-power-user-0.40.3/dist/dbt_core_integration.py", line 677, in compile_sql
    raise Exception(str(e))
Exception: Compilation Error in sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)
  'dict object' has no attribute 'nodes'

  > in macro find_model_node (macros/upstream_prod/find_model_node.sql)
  > called by macro default__ref (../utils/macros/global/ref.sql)
  > called by macro ref (../utils/macros/global/ref.sql)
  > called by sql_operation t_7e835b69b0844abe872beb17ada1bda3 (from remote system.sql)