Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metabase exposures cause dbt to crash when referencing existing questions / variables because of jinja interpolation #148

Closed
Startouf opened this issue Oct 18, 2022 · 2 comments · Fixed by #204
Labels
bug Something isn't working

Comments

@Startouf
Copy link

This happens when referencing other metabase questions in metabase

In the metabase exposures yml here is an extract of a problematic line

exposures:
  - name: my_viz
    description: "### Visualization: Table\n\nSee https://example.com/xx\n\
      \n#### Query\n\n```\nwith \nappointments as (\n  select * FROM `xxxx.fct_appointments`\
      \ \n),\nusers as (\n  select * from {{#161}}\n  where last_active_at_cache >\
      \ timestamp_sub(current_timestamp, interval 365 DAY)\n),\napts as (\n  SELECT\

I believe dbt tries to interpolate the metabase question references as jinja expression, thus causing problems

jinja2.exceptions.TemplateSyntaxError: unexpected char '#' at 276
  line 13
    select * from {{#161}}

This is likely to cause problems with every metabase custom variable/reference wrapped under {{}}

Is there a way to either post-process the exposures.yml to escape those characters, or find a way to disable dbt jinja interpolation for metabase exposures ?

@teamclaires
Copy link

teamclaires commented Jul 25, 2023

This issue is pretty huge, because it also affects your ability to dbt compile after creating an exposures file in your models/ directory. We get the following error when running dbt compile after successfully creating models/exposures.yml:

Compilation Error
  expected token 'end of print statement', got ':'
    line 8
      {{snippet: NameOfSnippet}}

Edit: There are two issues with this {{}} template string, the : and the whitespace between non-whitespace characters, which are both standard for snippets in Metabase. Adding a post-processing step to fix this file is non-trivial... the fact that exposures can create invalid yaml seems like a big issue.

@clanog
Copy link

clanog commented Dec 9, 2023

I found that if whatever is inside the brackets is quoted, it just works.

{{'like so'}}  
{{'and colons: also work'}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants