dbt relationship test compilation error: test definition dictionary must have exactly one key
Asked Answered
L

1

6

I'm a new user of dbt, trying to write a relationship test:

- name: PROTOCOL_ID
  tests:
    - relationships:
    to: ref('Animal_Protocols')
    field: id

I am getting this error:

Compilation Error
Invalid test config given in models/Animal_Protocols/schema.yml:
test definition dictionary must have exactly one key, got [('relationships', None), ('to', "ref('Animal_Protocols')"), ('field', 'id')] instead (3 keys)
@: UnparsedNodeUpdate(original_file_path='model...ne)

"unique" and "not-null" tests in the same file are working fine, but I have a similar error with "accepted_values".

I am using dbt cli version 0.21.0 with Snowflake on MacOS Big Sur 11.6.

Lithology answered 25/10, 2021 at 18:32 Comment(0)
R
20

You are very close! I'm 96% sure that this is an indentation issue -- the #1 pain point of working with YAML. The solution is that both to and field need to be indented below the relationships key as opposed to at the same level.

See the Tests dbt docs page for an example

  - name: PROTOCOL_ID
    tests:
      - relationships:
          to: ref('Animal_Protocols')
          field: id
Rummel answered 25/10, 2021 at 19:28 Comment(4)
Thank you! That was a good clue, though it wasn't the exact problem. My original post didn't show the indentation that I had. My editor was setup for 2 spaces of indentation at each level. That works for most levels (e.g. "-tests:") but not for the level immediately below "-relationships:". It worked once I changed the "to:" and "from:" from 2 to 4 spaces of indentation. Arrrrrgggggghhhhhh! I always knew that YAML's syntax is a bad idea.Lithology
...smacks head on desk, yup all the wayAntoneantonella
Ah thanks for your answer, I had a different problem (dbt expectations) but the answer was the same :)Eckert
My dear god, I was looking for this issue for a while, I changed from 2 to 4 spaces and it got solved. Thank you so much for adding this commentMoneybag

© 2022 - 2024 — McMap. All rights reserved.