dbt-labs / dbt-jsonschema

Apache License 2.0
109 stars 40 forks source link

Incorrect type when using Jinja where a number is expected #13

Closed brunocostalopes closed 1 year ago

brunocostalopes commented 1 year ago

The following raises a "Incorrect Type". Expected "number" error.

It's probably a slightly "unorthodox" use case and I'm not sure it can be fixed but thought I should raise anyway.

version: 2

sources:
  - name: schema_name
    tables:
      - name: table_name
        freshness:
          error_after: {
            count: "{{ var('source_freshness_low_volume_table') }}",
            period: hour
          }
joellabes commented 1 year ago

This is totally reasonable! If you wanted to have a go at resolving this, there is some prior art here:

https://github.com/dbt-labs/dbt-jsonschema/blob/26b2a7cf0cdbd30c46fe83af964efb1226b00e23/schemas/dbt_yml_files.json#L521-L532

If you created a new def called number_or_jinja_string, you could swap out https://github.com/dbt-labs/dbt-jsonschema/blob/26b2a7cf0cdbd30c46fe83af964efb1226b00e23/schemas/dbt_yml_files.json#L603-L606 for

                "count": {
                    "$ref": "#/$defs/number_or_jinja_string"
                },
brunocostalopes commented 1 year ago

You've made it sound super easy. Let me give it a go.

dave-connors-3 commented 1 year ago

@joellabes looks like this one might be solved?