question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set query_tag through macro

See original GitHub issue

Describe the bug

Trying to set query_tag in dbt_project.yml through a macro doesn’t work. Returns an error '<macro>' is undefined.

Steps To Reproduce

  1. Create a macro which returns some text.
  2. Use that macro as your query_tag, e.g:
models:
  query_tag: "{{ build_qtag('le_tag') }}" 

Expected behavior

The tag should be set from the macro… 😄

Screenshots and log output

Running with dbt=0.18.0
Encountered an error:
Compilation Error
  Could not render {{ build_qtag('le_tag') }}: 'build_qtag' is undefined

System information

Which database are you using dbt with?

  • snowflake

The output of dbt --version:

installed version: 0.18.0
   latest version: 0.18.1

Your version of dbt is out of date! You can find instructions for upgrading here:
https://docs.getdbt.com/docs/installation

Plugins:
  - postgres: 0.18.0
  - redshift: 0.18.0
  - bigquery: 0.18.0
  - snowflake: 0.18.0

(Note: The same issue exists on 0.18.1)

The operating system you’re using:

  • Docker, python:3.7
root@fa939f48db3d:/dbt# uname -a
Linux fa939f48db3d 5.8.0-7630-generic #32~1607010078~20.04~383a644-Ubuntu SMP Thu Dec 3 19:14:47 UTC 2 x86_64 GNU/Linux

The output of python --version: Python 3.7.9

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
praktisktcommented, Dec 9, 2020

I ran a small integration test (~100 models) and the only anomaly I could find was that the initial query (the one which actually sets the query_tag). I’ll let this run for a while and we’ll see what happens.

0reactions
jtcohen6commented, Dec 9, 2020

We’ve seen issues where folks try to run alter session commands in a pre-hook, e.g. to change session parameters or the default timezone. Because dbt closes the connection once done, Snowflake may end the session, causing the model SQL to then run in a different session (with different session parameters, defaults, and tags).

One solution there is to use sql_header instead of pre-hook (docs), but sql_header does not support late-rendering, which is the thing you’re after here.

Could you try this approach, and check the Snowflake query history to confirm that your model query ran with the tag you expect?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot set query_tag through macro · Issue #2942 · dbt-labs ...
Describe the bug Trying to set query_tag in dbt_project.yml through a macro doesn't work. Returns an error ' ' is undefined.
Read more >
[DBT] Set Snowflake Query Tag for each DBT model [Tip-2]
3 ways to configure query tag. Configure it in dbt_project.yml , the drawback in this approach is we can only add string, can't...
Read more >
snowflake cloud data platform - Adding Query Tag to DBT Test
The default macro in the dbt package for snowflake, in line 3 calls a macro named set_query_tag(), that it's defined here.
Read more >
OpenQuery Macro Action - Microsoft Support
You can use the OpenQuery macro action in Access databases to open a select or crosstab query in Datasheet view, Design view, or...
Read more >
Creating Memory, Expression, and Query Tags
To Create Memory Tags ... Expression Tags cannot be written to. ... The value of a SQL Query tag comes from the database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found