dbt-metabase icon indicating copy to clipboard operation
dbt-metabase copied to clipboard

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

Open heberaguilar opened this issue 3 years ago • 4 comments

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.

heberaguilar avatar Nov 02 '21 10:11 heberaguilar

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.

gouline avatar Nov 02 '21 23:11 gouline

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 ?

heberaguilar avatar Nov 03 '21 12:11 heberaguilar

@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.

erika-e avatar Nov 03 '21 12:11 erika-e

@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.

gouline avatar Nov 03 '21 23:11 gouline