Pin month-relative integration tests to a frozen reference date - #67
Draft
Pádraic Slattery (pgoslatara) wants to merge 1 commit into
Draft
Pin month-relative integration tests to a frozen reference date#67Pádraic Slattery (pgoslatara) wants to merge 1 commit into
Pádraic Slattery (pgoslatara) wants to merge 1 commit into
Conversation
The last_month_* / next_month_* macros compile to SQL anchored on current_date. The integration model materialises as a table, freezing those values at `dbt run` time, while test_dates.yml re-evaluated the same macros at `dbt test` time. When the two steps straddle a month boundary in the configured time zone (America/Los_Angeles), they disagree and the tests fail spuriously — then pass on re-run. Capture today() once as a frozen as_of_date column and derive the six month assertions from that stored date instead of a fresh today(), so run and test can no longer disagree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
duckdbintegration tests failed intermittently (e.g. run 28499584995) on the six month-relative assertions —last_month_number,last_month_name,last_month_name_short,next_month_number,next_month_name,next_month_name_short— and then passed on re-run with no code changes. This is a month-boundary race, not a real regression.The
last_month_*/next_month_*macros compile to SQL anchored oncurrent_date(viadbt_date.today(tz)). The integration project materialises models astableand setsdbt_date:time_zone: "America/Los_Angeles". So the model column is frozen atdbt runtime, whiletest_dates.ymlre-evaluated the same macros atdbt testtime. When the two steps straddle midnight-of-the-1st in that time zone (07:00–08:00 UTC depending on DST), they resolve to different months and the assertion fails. The failing run built the model at 23:59:56 PDT (June 30) and asserted at 00:00:01 PDT (July 1); the re-run ran entirely on one side of the boundary, so it was green.This pins the reference date so the two invocations can't disagree:
get_test_dates.sqlnow capturestoday()once as a frozenas_of_datecolumn (evaluated in the same statement as the month columns, so it shares their exact instant), and the six assertions intest_dates.ymlderive their expected values from that stored column viadbt.date_trunc/dbt.dateaddinstead of a freshtoday(). The macros are still exercised atdbt runtime, so coverage is unchanged.Verified locally with
tox -e dbt_integration_duckdb: 36/36 tests pass.