Skip to content

Fix: Set dbt execute variable for parse time and run time accordingly#5327

Closed
themisvaltinos wants to merge 1 commit intomainfrom
themis/execute
Closed

Fix: Set dbt execute variable for parse time and run time accordingly#5327
themisvaltinos wants to merge 1 commit intomainfrom
themis/execute

Conversation

@themisvaltinos
Copy link
Contributor

This update sets the dbt variable execute to False during parse-time and true for run time. Dbt models and macros have conditional logic which is guarded with this flag for runtime execution:

{% if execute %}
  {% set result = run_query("SELECT COUNT(*) FROM my_table") %}
  SELECT {{ result.columns[0][0] }} as count
{% endif %}

These jinja expressions might depend on the data warehouse or to objects (like graph) not available at parse time, so the execute ensure these only should run at the runtime stage.

dbt docs: https://docs.getdbt.com/reference/dbt-jinja-functions/execute

{
"adapter": adapter,
"execute": True,
"execute": isinstance(adapter, RuntimeAdapter),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we should not do this. execute is set unconditionally to True for a reason. Since we used the rendered query for change detection and categorization we want to follow the execution path during rendering. If we happen to encounter the adapter call we fail and return None which indicates that the query cannot be rendered and categorized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we used the rendered query for change detection and categorization we want to follow the execution path during rendering. If we happen to encounter the adapter call we fail and return None which indicates that the query cannot be rendered and categorized.

I see was wondering about this, thanks that makes sense. and I guess now that we can fail and still proceed later to runtime this can't lead to any issues

Copy link
Collaborator

@izeigerman izeigerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't graph available at load time?

@themisvaltinos
Copy link
Contributor Author

Why isn't graph available at load time?

I was mirroring dbt, but since we already have the manifest loaded you're right it will be available at "our parse time", it's a different distinction. I will proceed to add it

@georgesittas georgesittas deleted the themis/execute branch September 9, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants