cube-js / cube_dbt

dbt integration for Cube
7 stars 3 forks source link

YAMLException: bad indentation of a sequence entry #3

Closed SkinnyPigeon closed 1 year ago

SkinnyPigeon commented 1 year ago

When using the Jinja templating, we are experiencing an issue with the indentation. The description and sql_table values of the string are indented by an extra 4 spaces than is needed.

We have checked this by printing out the model and stripping out the additional spaces

model/globals.py

from cube import TemplateContext
from cube_dbt import Dbt

dbt = Dbt.from_file("./manifest.json")
template = TemplateContext()

@template.function("dbt_models")
def dbt_models():
    return dbt.models

@template.function("dbt_model")
def dbt_model(name):
    print(dbt.model.as_cube()).replace('    ',''))
    return dbt.model(name)

model/cubes/deliveries.yml

{% set model = dbt_model('delivery_base') %}

cubes:
  - {{ model.as_cube()) }}

    dimensions:
      {{ model.as_dimensions() }}
SkinnyPigeon commented 1 year ago

As an update, if we do the following, the cube compiles:

{% set model = dbt_model('delivery_base') %}

cubes:
  - name: {{ model.name }}
    description: {{ model.description }}
    sql_table : {{ model.sql_table }}

However, if we then add in the dimensions, we get an error: dimensions must be defined as an array:

{% set model = dbt_model('delivery_base') %}

cubes:
  - name: {{ model.name }}
    description: {{ model.description }}
    sql_table : {{ model.sql_table }}

    dimensions:
      {{ model.as_dimensions() }}

The weird thing is that running this script succeeds in creating the correctly formatted file:

from cube_dbt import Dbt

dbt = Dbt.from_file("./manifest.json")

def dbt_model(name):
    return dbt.model(name)

model = dbt_model("delivery_base")

output = f"""
cubes:
  - { model.as_cube() }
    dimensions:
      { model.as_dimensions() }

"""

with open("./model/cubes/delivery_base.yml", "w") as f:
    f.write(output)
igorlukanin commented 1 year ago

Hi @SkinnyPigeon 👋 Thanks for a very detailed report!

Could you please check if upgrading to cube_dbt==0.6.0 changes anything for you? We've made a few fixes related to Jinja escaping. (If you don't have a version in your requirements.txt file, the package would update automatically, just re-run the build or go to a fresh dev mode session.)

dimensions must be defined as an array

I'm almost 100% sure that this error would be gone after updating.

The description and sql_table values of the string are indented by an extra 4 spaces than is needed.

I'm not sure about this one but let's see if anything changes after the update.

SkinnyPigeon commented 1 year ago

This is completely fixed. Thanks so much for the super quick turnaround on this! I have no idea how you guys manage to be so productive!

{% set model = dbt_model('delivery_base')%}

cubes:
  - {{ model.as_cube() }}

    dimensions:
      {{ model.as_dimensions() }}

    measures:
      - name: count
        type: count