gouline / dbt-metabase

dbt + Metabase integration
https://pypi.org/project/dbt-metabase/
MIT License
442 stars 63 forks source link

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

Closed Startouf closed 5 months ago

Startouf commented 1 year ago

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 commented 11 months ago

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 commented 7 months ago

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

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