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

[Bug] Unit tests not working for incremental models

Open CraigWilson-ZOE opened this issue 5 months ago • 9 comments

Is this a new bug in dbt-core?

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

Current Behavior

When running a unit tests for an incremental model I am getting the following error:

14:41:49    Database Error in unit_test unit_test__int_barcode_scanned_events_incremental_mode (models/silver/intermediate/food_logging/tests.yml)
  Syntax error: Unexpected "." at [18:44]

Expected Behavior

The unit tests to pass

Steps To Reproduce

  1. Environment is:
  • dbt 1.8.6
  • dbt bigquery 1.8.2
  • dbt-adapters 1.5.0
  • dbt-utils 1.3.0
  1. incremental model configuration:
{{
    config(
        materialized='incremental',
        incremental_strategy='insert_overwrite',
        unique_key='event_id',
        partition_by={
            "field": "date_day",
            "data_type": "date"
        }
    )
}}
  1. Unit test config:
unit_tests:
  - name: unit_test__int_barcode_scanned_events_incremental_mode
    description: Unit test for int_barcode_scanned_events in incremental mode
    model: int_barcode_scanned_events
    overrides:
      macros:
        is_incremental: true
    given:
        - input: ref('stg_insights_mixpanel_event')
          format: csv
          fixture: raw_mixpanel_events
        - input: this
          format: csv
          fixture: incremental_int_barcode_scanned_events
    expect:
        format: csv
        fixture: expected__int_barcode_scanned_events

Relevant log output

...
15:06:35  3 of 3 ERROR int_barcode_scanned_events::unit_test__int_barcode_scanned_events_incremental_mode  [ERROR in 1.31s]
...
15:06:58    Database Error in unit_test unit_test__int_barcode_scanned_events_incremental_mode (models/silver/intermediate/food_logging/tests.yml)
  Syntax error: Unexpected "." at [18:44]

Environment

- OS: macos 14.3.1
- Python: Python 3.12.2
- dbt: 1.8.6

Which database adapter are you using with dbt?

bigquery

Additional Context

The SQL that seems to be produced and is causing the error is the following:

/* {"app": "dbt", "dbt_version": "1.8.5", "profile_name": "default", "target_name": "development", "node_id": "unit_test.dbt_bq_elt.int_barcode_scanned_events.unit_test__int_barcode_scanned_events_incremental_mode"} */


      
        
            select distinct
                table_schema,
                table_name,
                
            case table_type
                when 'BASE TABLE' then 'table'
                when 'EXTERNAL TABLE' then 'external'
                when 'MATERIALIZED VIEW' then 'materializedview'
                else lower(table_type)
            end as `table_type`


            from `dbt-development-joinzoe`..INFORMATION_SCHEMA.TABLES
            where lower(table_name) like lower ('')
                and lower(table_name) not like lower ('')

CraigWilson-ZOE avatar Sep 10 '24 15:09 CraigWilson-ZOE