[v2 Bug] DuckDB unit test fixtures cast TIMESTAMP WITH TIME ZONE columns as `timestamp without time zone`, shifting values by the session timezone
Is this a new bug in dbt v2.x compared to the latest version of dbt 1.x?
- I believe this is a new bug in dbt v2.x
- I have searched the existing issues and could not find a duplicate
Current Behavior
For a model column of type TIMESTAMP WITH TIME ZONE, the expect fixture value is cast as timestamp without time zone in the generated unit test SQL (target/compiled/<project>/models/<test>.sql):
CAST('2024-01-01 00:00:00+00' AS timestamp without time zone) AS ts_tzThe +00 offset is dropped, and the UNION ALL with the actual column re-interprets the value in the session timezone. With TimeZone = America/Sao_Paulo, expected renders as 2024-01-01T00:00:00-03:00 while actual is 2023-12-31T21:00:00-03:00, so a correct expectation is three hours off. With TZ=UTC the same test passes.
Today this is masked by #15894 (timestamp columns are never compared, both sides render as [unsupported]). Once that is fixed, correct tz-aware expectations fail on DuckDB outside UTC.
Expected Behavior
The fixture should be cast to the column's actual type (timestamp with time zone) so '2024-01-01 00:00:00+00' keeps its offset and matches the model output in any session timezone. This is what dbt-core 1.12.5 with dbt-duckdb generates:
cast('2024-01-01 00:00:00+00' as TIMESTAMP WITH TIME ZONE)Steps To Reproduce
models/ts_model.sql:select timestamptz '2024-01-01 00:00:00+00' as ts_tzmodels/ts_model.yml:unit_tests: - name: tz_fixture_matches model: ts_model given: [] expect: rows: - {ts_tz: "2024-01-01 00:00:00+00"}- DuckDB profile, session timezone other than UTC (for example
TZ=America/Sao_Paulo dbt build). - Inspect
target/compiled/<project>/models/tz_fixture_matches.sql: the expected CTE caststs_tzastimestamp without time zone. - Re-run with
TZ=UTC dbt buildand compare.
Relevant log output
With the comparison fix from #15894 applied locally, the diff table shows:
| ts_tz |
| 2024-01-01T00:00:00-03:00 -> 2023-12-31T21:00:00-03:00 |Environment
- OS: macOS
- CPU: ARM
- dbt distribution and version: dbt 2.0.6 (Core); OSS build from
mainat 7e4e937c4 for the diff output. Compared against dbt-core 1.12.5 + dbt-duckdb 1.11.0, where the same test passes.
Which database adapter are you using?
duckdb
Is this a discrepancy vs. dbt 1.x?
- Yes — this works in dbt 1.x but not in dbt v2.x
Additional Context
Cause: the type formatter in crates/dbt-adapter/src/sql_types.rs renders every DataType::Timestamp(_, _) as timestamp without time zone, ignoring the timezone on the Arrow type. Found while working on #15894; that fix does not change fixture typing.
Source: dbt-labs/dbt-core