Repository navigation
fix(dedupe): only count import locks held in the current database - #16397
Merged
Merged
Conversation
The excess-duplicate delete read import-lock holders from pg_locks, which lists advisory locks for every database on the server. Advisory locks only conflict within their own database, so a test was skipped whenever another database's test with the same id was being imported: another DefectDojo instance on a shared cluster, or another --parallel test worker. That made test_duplicate_of_a_test_just_reimported_is_deleted_once_the_import_has_ended flaky in the merge queue. Filter the holder query to the current database, and add a regression test that holds the lock from another database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
blakeaowens
approved these changes
Oct 17, 2026
devGregA
approved these changes
Oct 17, 2026
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.
Shortcut: sc-16686
Description
test_duplicate_of_a_test_just_reimported_is_deleted_once_the_import_has_ended(added in #16379) failed in 4 of the last 5 failed merge-queue runs, on amd64 and arm64, with Locations on and off. The flake comes from a real bug.The excess-duplicate delete skips tests whose import lock is held. To find those tests,
_import_lock_holdersreadspg_locks. Butpg_lockslists advisory locks for every database on the server, and an advisory lock only conflicts inside its own database. So a test was left out of the delete whenever a test with the same id was being imported in a different database:--parallelworker, since each worker has its owntest_defectdojo_Ndatabase;The per-chunk try-lock (
tests_under_import_now) was already scoped to the database. Only the selection-time read and the abandoned-lock check used the unfiltered view.I confirmed this on a scratch Postgres: with the lock held in
db_a, the current holder query run fromdb_breports the test as locked, whilepg_try_advisory_xact_lockfromdb_bsucceeds.The fix filters the holder query to
current_database().Test results
New regression test
test_import_lock_in_another_database_does_not_hold_back_the_deleteholds the lock from thepostgresdatabase and checks that the duplicate is still deleted.an import lock held in another database kept this database's excess duplicate.unittests.test_dedupe_delete_commit_racepass locally.ruff check(0.16.10) is clean.Documentation
None needed.
🤖 Generated with Claude Code