gouline / dbt-metabase

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

KeyError: 'fk_target_table' when when column has semantic type type/FK and has no tests #75

Closed heberaguilar closed 12 months ago

heberaguilar commented 2 years ago

Hello,

I've got a KeyError: 'fk_target_table' when propagating data from dbt table to Metabase. This error occurs in two specific cases:

  1. A column in the the schema.yml has a semantic type equal to type/FK but it has not a tests section within it.
  2. A column in the the schema.yml has a semantic type equal to type/FK but its tests section contains a dbt_utils.relationships_where test within it.
gouline commented 2 years ago

Explicitly setting type/FK is not supported, because there's no way to specify the target table. You can only set the relationship test and then it will implicitly apply type/FK with the target table specified in your relationship test.

heberaguilar commented 2 years ago

Hello @gouline, Thank you very much for your rapid answer. That explains and solves the error in case 1: we need to use a relationship test. For case 2, do you know if dbt-metabase recognize a test of the type dbt_utils.relationships_where ?

erika-e commented 2 years ago

@gouline Is that a Metabase limitation? In the UI it's supported to make something a foreign key without specifying a target table. In the case of numeric IDs, e.g. 1, 2, 3 giving them a key type allows them to be used in the query builder as IDs. Without, the query builder assumes they're numbers and tries to bin them.

gouline commented 2 years ago

@heberaguilar Unfortunately, not currently. It has the same to and field fields though, so you could easily implement it here for the folder parser and here for the manifest parser.

@erika-e This is a dbt-metabase limitation, because it tries to be smart and infer your foreign key without explicitly specifying it. You could make the extraction of fk_target_table and fk_target_field optional here, if that's a use case that you need.