Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-1977] [Regression] 'BaseResult' object has no attribute 'node' #6796

Closed
2 tasks done
fradeleo opened this issue Jan 31, 2023 · 6 comments · Fixed by #6899
Closed
2 tasks done

[CT-1977] [Regression] 'BaseResult' object has no attribute 'node' #6796

fradeleo opened this issue Jan 31, 2023 · 6 comments · Fixed by #6899
Assignees
Labels
bug Something isn't working regression
Milestone

Comments

@fradeleo
Copy link

fradeleo commented Jan 31, 2023

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

Hi,

I recently upgraded to dbt core 1.4.1 and dbt bigquery 1.4.0 and I've started receiving a python error using exceptions.raise_compile_error in a on-run-start hook macro. Everything was working fine before the upgrade.

Macro and logs attached below.

I tried to substitute the exceptions.raise_compile_error with a log() message just to check if it was indeed the exception causing the issue, and I didn't bump into any errors.

Expected Behavior

This setup worked before. If a single row was returned by the query, an error would be raised and dbt run would not start at all.

Steps To Reproduce

In macros folder, create an export_table_check.sql file with the following content (change table name and column name based on your own table in bigq).


{% macro export_table_check() %}

    {% set table = '12_exported_records' %}

    {% set query %}
        SELECT column_name
        FROM {{ref(table)}}
        LIMIT 1
    {% endset %}

    {%- if flags.WHICH in ('run', 'build') -%}
        {% set results = run_query(query) %}
        {% if execute %}
            {%- if results.rows -%}
                {{ exceptions.raise_compiler_error("ON_RUN_START_CHECK_NOT_PASSED: Data already exported. DBT Run aborted.") }}
            {% else -%}
                {{ log("No data found in " ~ table ~ " for current day and runtime region. Proceeding...", true) }}
            {%- endif -%}
        {%- endif -%}
    {%- endif -%}
{% endmacro %}


In dbt_project:

on-run-start: 
- "{{ export_table_check() }}"

Relevant log output

15:41:26  Running with dbt=1.4.1
15:41:26  Found 31 models, 96 tests, 0 snapshots, 0 analyses, 349 macros, 1 operation, 3 seed files, 31 sources, 0 exposures, 0 metrics
15:41:26  
15:41:28  
15:41:28  Running 1 on-run-start hook
15:41:28  Database error while running on-run-start
15:41:28  Concurrency: 8 threads (target='dev')
15:41:28  
15:41:28  1 of 1 START sql table model prioritization.00a_program_specification_exploded . [RUN]
15:41:31  1 of 1 OK created sql table model prioritization.00a_program_specification_exploded  [CREATE TABLE (213.0 rows, 62.9 KB processed) in 2.81s]
15:41:31  
15:41:31  Finished running 1 table model in 0 hours 0 minutes and 4.82 seconds (4.82s).
15:41:32  Encountered an error:
'BaseResult' object has no attribute 'node'
15:41:32  Traceback (most recent call last):
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/main.py", line 135, in main
    results, succeeded = handle_and_check(args)
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/main.py", line 198, in handle_and_check
    task, res = run_from_args(parsed)
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/main.py", line 245, in run_from_args
    results = task.run()
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/task/runnable.py", line 472, in run
    result = self.execute_with_hooks(selected_uids)
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/task/runnable.py", line 436, in execute_with_hooks
    self.after_run(adapter, res)
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/task/run.py", line 443, in after_run
    database_schema_set: Set[Tuple[Optional[str], str]] = {
  File "/home/deleof/anaconda3/envs/prio/lib/python3.9/site-packages/dbt/task/run.py", line 446, in <setcomp>
    if r.node.is_relational
AttributeError: 'BaseResult' object has no attribute 'node'

Environment

- OS: Ubuntu 20.04 LTS
- Python: 3.9.0, 3.10.0
- dbt: 1.4.1

Which database adapter are you using with dbt?

bigquery

Additional Context

No response

@fradeleo fradeleo added bug Something isn't working triage labels Jan 31, 2023
@github-actions github-actions bot changed the title [Bug] Error when running [CT-1977] [Bug] Error when running Jan 31, 2023
@jtcohen6 jtcohen6 added this to the v1.4.x milestone Jan 31, 2023
@jtcohen6
Copy link
Contributor

Thanks for opening @fradeleo!

Lame fix: Change task/run.py:446 to check if the result has an attribute node first.

        database_schema_set: Set[Tuple[Optional[str], str]] = {
            (r.node.database, r.node.schema)
            for r in results
            if (hasattr(r, "node") and r.node.is_relational)
            and r.status not in (NodeStatus.Error, NodeStatus.Fail, NodeStatus.Skipped)
        }

Better fix: Figure out what we changed in v1.4 that actually causes this hook result to pass through RunTask.after_run, in a way that it wasn't previously. I tagged this Team:Language and logging because I have a hunch that it's to do with a change to our exception classes... but it's possible that the presence of exceptions.raise_compiler_error is a red herring

@jtcohen6 jtcohen6 changed the title [CT-1977] [Bug] Error when running [CT-1977] [Bug] raise_compiler_error in hook -> 'BaseResult' object has no attribute 'node' Jan 31, 2023
@jtcohen6 jtcohen6 removed the triage label Jan 31, 2023
@christopherekfeldt
Copy link

We got the same issue and reverted our upgrades of dbt-core 1.4.1 and dbt-bigquery 1.4.0 since we found it hard to retrace what was causing the issue to be triggered..

@christopherekfeldt
Copy link

@emmyoop will this be solved in the next release of dbt-core?

@jtcohen6
Copy link
Contributor

jtcohen6 commented Feb 9, 2023

@christopherekfeldt We've backported the fix to 1.4.latest (#6904), so this will be included in the next v1.4.x patch release. We'll have a release candidate soon to test out & confirm the fix is working!

@jtcohen6 jtcohen6 removed the logging label Feb 9, 2023
@christopherekfeldt
Copy link

Thanks guys! Keep up the amazing work. We love dbt

@emmyoop
Copy link
Member

emmyoop commented Feb 9, 2023

@christopherekfeldt thanks for reporting the regression with such a great reproduction case! Always makes it easier to figure out what's happening.

@jtcohen6 jtcohen6 changed the title [CT-1977] [Bug] raise_compiler_error in hook -> 'BaseResult' object has no attribute 'node' [CT-1977] [Regression] 'BaseResult' object has no attribute 'node' Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants