Skip to content

fix: use run_query in get_column_values to avoid statement name collision#1111

Open
Harish-Ranjith wants to merge 1 commit into
dbt-labs:mainfrom
Harish-Ranjith:fix/get-column-values-macro-collision
Open

fix: use run_query in get_column_values to avoid statement name collision#1111
Harish-Ranjith wants to merge 1 commit into
dbt-labs:mainfrom
Harish-Ranjith:fix/get-column-values-macro-collision

Conversation

@Harish-Ranjith

Copy link
Copy Markdown

Fixes #1079

The macro uses a hardcoded name in statement('get_column_values') which gets stored in the global context. When two models call this macro in the same dbt run, the second call hits MacroResultAlreadyLoadedError because the name is already registered.

Switched to
un_query() which returns results directly without touching global state. Also updated result access to match the agate.Table API.

Tested locally with dbt-duckdb by calling the macro twice in one model - no error after the fix.

Fixes dbt-labs#1079. When multiple models call get_column_values in the same dbt invocation, the hardcoded statement name causes MacroResultAlreadyLoadedError on the second call. Replacing with run_query() eliminates global name dependency entirely. Updated result access to use agate.Table API.
@Harish-Ranjith Harish-Ranjith requested a review from a team as a code owner June 28, 2026 18:13
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.

get_column_values raises MacroResultAlreadyLoadedError when using sqlfluff dbt templater or dbt Cloud CLI`

1 participant