dbt-core
dbt-core copied to clipboard
[Regression] `show` command should more gracefully handle/fail queries that fail to execute
Describe the feature
I'm noticing that #8166 is happening again on dbt-core==1.7.11 with multiple adapters.
If as user calls dbt show on a model or inline-query that the underlying data platform does not like, dbt should quit and return the database error. Instead, show continues, which results in an stack trace resulting from dbt trying to call Agate.Table.print_table() on a None.
The undesirable behavior is consistent across both the --inline and -s some_model usage patterns.
Reproducible Example
input
# notice `SLECT`'s missing `E`
dbt show --inline "SLECT 1 as my_col"
output
14:25:25 Running with dbt=1.7.11
14:25:26 Registered adapter: snowflake=1.7.3
14:25:26 Unable to do partial parsing because config vars, config profile, or config target have changed
14:25:26 Unable to do partial parsing because a project dependency has been added
14:25:27 Found 6 models, 3 seeds, 20 tests, 0 sources, 0 exposures, 0 metrics, 430 macros, 0 groups, 0 semantic models
14:25:27
14:25:28 Concurrency: 10 threads (target='snowflake')
14:25:28
14:25:29 CANCEL query sql_operation.jaffle_shop.inline_query ............................ [CANCEL]
14:25:29
14:25:29 Database Error in sql_operation inline_query (from remote system.sql)
001003 (42000): SQL compilation error:
syntax error line 3 at position 8 unexpected 'SLECT'.
14:25:29 Encountered an error:
'NoneType' object has no attribute 'print_table'
14:25:29 Traceback (most recent call last):
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 91, in wrapper
result, success = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 76, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 169, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 198, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 245, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/requires.py", line 278, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/cli/main.py", line 418, in show
results = task.run()
^^^^^^^^^^
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/task/runnable.py", line 521, in run
self.task_end_messages(result.results)
File "/Users/dataders/miniforge3/envs/dbt/lib/python3.11/site-packages/dbt/task/show.py", line 93, in task_end_messages
table.print_table(output=output, max_rows=None)
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'print_table'
Describe alternatives you've considered
Perhaps there's a try-catch that if there's a database error and no ResultSet is returned, then dbt show can return/print an empty Agate table? or even a table with the database error in it?
Who will this benefit?
All users of dbt show as well as users of downstream tools that make use of the same.
Are you interested in contributing this feature?
No response
Anything else?
No response
@dataders are you still seeing this issue in dbt 1.7 or 1.8?
I wasn't able to reproduce this with Python 3.10.10 and the same versions of dbt-core and dbt-snowflake as you -- here's what I got instead:
(dbt_1.7) $ dbt show --inline "SLECT 1 as my_col"
23:20:10 Running with dbt=1.7.11
23:20:12 Registered adapter: snowflake=1.7.3
23:20:12 Found 1 model, 1 seed, 0 sources, 0 exposures, 0 metrics, 430 macros, 0 groups, 0 semantic models
23:20:12
23:20:13 Concurrency: 10 threads (target='snowflake')
23:20:13
23:20:14 Encountered an error:
Runtime Error
Database Error in sql_operation inline_query (from remote system.sql)
001003 (42000): SQL compilation error:
syntax error line 3 at position 8 unexpected 'SLECT'.
(dbt_1.7) $