Handle errors when invoking run_query or call statement

I would like to use either a call statement or a run_query block to fetch the table history for a given delta lake table and use the results in a test (the use case is checking the table size as of a given version and seeing if it has changed unexpectedly).

Unfortunately if the table doesn’t exist in one’s dev schema, dbt compile throws an error because the call statementquery throws a table does not exist error, so this breaks local development for my team.

I’d like to do something like this but none of the documentation or examples I’ve seen indicate if/how to do so:

  • try a call statement
  • If the query throws an error, execute some sql that always passes the test case
  • Otherwise run the intended test code

I found a solution, which relies on checking if the relation in question exists first. I posted it here.

Inspired by @edbizarro 's show and tell here. :pray:

1 Like