DataRecce / recce

The dbt data-validation toolkit for teams that care about building better data
https://datarecce.io
Apache License 2.0
252 stars 6 forks source link

Resetting invocation_context on generate_sql function when dbt_version > 1.8 #404

Closed jefersonmsantos closed 2 months ago

jefersonmsantos commented 2 months ago

Fix 405

On new dbt 1.8 version there is error LookupError: <ContextVar name='DBT_INVOCATION_CONTEXT_VAR' at 0x10c4889f0> when using function "Run query" or "Run diff". This happens because class DbtAdapter sets the invocation context with function set_invocation_context({}) when dbt version is 1.8, but on tasks/query.py file the default_context is regenererated before calling function generate_sql from DbtAdapter.

image image

To fix this, added a new call of set_invocation_context({}) on start of function generate_sql if dbt version is greater or equal than 1.8.

PR checklist

What type of PR is this? Bug fix

What this PR does / why we need it: Added a new call of set_invocation_context({}) on start of function generate_sql if dbt version is greater or equal than 1.8 to fix the issue described below.

With the fix, Run Diff works fine with dbt version 1.8:

image

Tests: image

Which issue(s) this PR fixes: Fix 405 When using new dbt 1.8 version, Run Diff feature will throw error LookupError: <ContextVar name='DBT_INVOCATION_CONTEXT_VAR' at 0x10c4889f0>

This happens because class DbtAdapter sets the invocation context with function set_invocation_context({}) when dbt version is 1.8, but on tasks/query.py file the default_context is regenererated before calling function generate_sql from DbtAdapter.

image

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

"NONE"

popcornylu commented 2 months ago

Thanks for your PR. image Could you please address the flake8 issue? Everything else looks good to me!

jefersonmsantos commented 2 months ago

Thanks for your PR. image Could you please address the flake8 issue? Everything else looks good to me!

Addressed. image