Skip to content

[BUG] incremental model failing on BQ due to tmp_relation has no type #769

@kbrock91

Description

@kbrock91

Describe the bug
incremental (merge) models are failing because the tmp_relation object does not have a type. the incremental table itself build successfully in BQ, but the step to drop the temp relation fails. this occurs when the on_schema_change config is set such that a tmp_relation would be created (e.g. anything other than ignore (fail, append_new_columns, sync_all_columns))

20:39:52 error: dbt1501: Error executing materialization macro '<dbt project>.materialization_incremental_bigquery' for model model.<dbt project>.<dbt model name>.v1: Failed to eval the compiled Jinja expression invalid operation: AdapterError: Configuration error: relation has no type
(in compiled/models/<model file path>.sql:1:26)
(in macros/dbt-labs-repro/bq_incremental_macro.sql:191:5)
  --> macros/dbt-labs-repro/bq_incremental_macro.sql:191:5

the error message above is referencing a materialization override as i was troubleshooting, but got the same error when using the default materialization

if i override the incremental materialization and explicitly set the type to table, the whole command is successful.

I believe we may need to add the following to the incremental materialization, similar to how to incorporate the type on the target_relation here
{% set tmp_relation_table = tmp_relation.incorporate(type='table') %}

What version of dbt Fusion is this bug in? (find out by running dbt --version)
dbt-fusion 2.0.0-preview.17

Is this a discrepancy between the dbt Fusion Engine and dbt Core? Check one.

  • YES
  • NO

To Reproduce
Please submit one of the following

  1. Create any dbt incremental model with on_schema_change='append_new_columns' --> which should create a temp table based on the materialization logic
{{
    config(
        materialized='incremental',
        on_schema_change='append_new_columns'
    )
}} 
  1. On an incremental run (not a full-refresh), see the that table gets successfully updated, but the dbt command overall fails (due to temp table not able to drop because of error error: relation has no type)

Expected behavior
incremental model runs successfully, tmp table is successfully dropped

Screenshots
If applicable, add screenshots to help explain your problem.

Operating System and CPU Type (please complete the following information):
running dbt Studio

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions