test(denies): give each xdist worker its own deny principal - #823
Merged
axellpadilla merged 2 commits intoAug 19, 2026
Merged
Conversation
The denies suite created and dropped one database-wide user,
`dbt_deny_reader`, from a class-scoped fixture shared by all eight test
classes. A database principal is database-scoped: unlike
`project.test_schema` it is not isolated per test. Under `pytest -n auto`
(how `make functional` runs) the classes are spread across worker
processes sharing one TestDB, so the first class to finish dropped the
user out from under every class still running, taking its
sys.database_permissions rows with it.
Nothing failed loudly at that point, because apply_denies is
deliberately warn-and-skip on an absent principal: the rebuild succeeded
having applied no DENY, and the assertions saw an empty set --
`assert ('SELECT', 'dbt_deny_reader') in set()`. Six of the eight tests
failed this way, non-deterministically and only under xdist.
Derive the principal name from PYTEST_XDIST_WORKER instead. Classes on
one worker run sequentially, so per-worker names are enough to keep
setup and teardown from overlapping. The model templates carry a
`__DENY_PRINCIPAL__` placeholder swapped at import; str.format and
f-strings are unusable on them because they are Jinja and `{{ config() }}`
would be eaten as an escaped brace.
Test-only: no adapter behaviour changes.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
The
deniessuite failed non-deterministically underpytest -n auto— which is howmake functionalruns it. Six of the eight tests, different ones each time. It passedreliably single-process.
Cause
The suite created and dropped one database-wide user,
dbt_deny_reader, from aclass-scoped fixture shared by all eight test classes. A database principal is
database-scoped: unlike
project.test_schema, it is not isolated per test. xdistspreads the classes across worker processes sharing one TestDB, so the first class to
finish dropped the user out from under every class still running, taking its
sys.database_permissionsrows with it.Nothing failed loudly at that point, because
apply_deniesis deliberately warn-and-skipon an absent principal. The rebuild succeeded having applied no
DENY, and the assertionssaw an empty set:
Fix
Derive the principal name from
PYTEST_XDIST_WORKER(dbt_deny_reader_gw3, or_mainoffxdist). Classes on one worker run sequentially, so per-worker names are enough to keep
setup and teardown from overlapping.
The model templates carry a
__DENY_PRINCIPAL__placeholder swapped at import via a smallwith_principal()helper.str.formatand f-strings are unusable on them — they're Jinja,and
{{ config(...) }}would be eaten as an escaped brace.Test-only: no adapter behaviour changes.