dbt-labs / dbt-labs/dbt-adapters

[Bug] full refresh of failed model with new partition schema fails on __dbt_tmp

Open
#541 0 comments 0 reactions 0 assignees View on GitHub
pkg:dbt-bigquery type:bug
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this a new bug in dbt-bigquery?

- [X] I believe this is a new bug in dbt-bigquery
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

If I change partition columns of an incremental model and forget to manually do a full refresh the dbt job will throw an error. This is expected. I will then do a full refresh of the model using `dbt build --select --full-refresh --target prod --debug` and the model is marked as success.
What is not apparent is that the __dbt_tmp table will linger until the next time the full build is run.
The dbt build job will fail on the next run, however, due to the fact that bigquery doesn't allow partition changes in a `create or replace` statement.

### Expected Behavior

A full refresh of a model will drop the `__dbt_tmp` table.

### Steps To Reproduce

1. Change partition schema on incremental model
2. Allow model to fail in `dbt build` job
3. Do a manual `--full-refresh`
4. Run the `dbt build` job again

### Relevant log output

```shell
12:52:35 Database Error in model (models/.sql)
Cannot replace a table with a different partitioning spec. Instead, DROP the table, and then recreate it. New partitioning spec is interval(type:day,field:p_date) and existing spec is none
12:52:35

```

### Environment

```markdown
- OS: Alpine (container python:3.11-slim)
- Python: 3.11
- dbt-core: 1.8.4
- dbt-bigquery: 1.8.2
```

### Additional Context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.