Can't purge projects that have project oauth clients#4807
Merged
Conversation
The test set Mix.shell(Mix.Shell.Process) in setup without restoring it. Mix.shell/1 is global VM state, so once this test ran the override leaked into every subsequent test for the rest of the suite. When seed-based test ordering interleaved an icons test before InstallSchemasTest's tally assertion, Mix.shell().info(...) sent a message instead of writing to stdout and capture_io got "" — surfacing as an intermittent failure. Snapshot Mix.shell() before the override and restore it in on_exit.
The project_oauth_clients FK was created with the default `on_delete: :nothing`, and `ProjectHook.handle_delete_project/1` didn't remove the join rows before `Repo.delete(project)`. Any soft-deleted project with an associated OAuth client crashed the daily purge_deleted Oban job with `project_oauth_clients_project_id_fkey`. Add `project_oauth_clients_query/1` and clean those rows alongside the other project-scoped deletes. The OAuth client itself is not project-scoped and is left intact.
Security Review ✅
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4807 +/- ##
=======================================
- Coverage 90.3% 90.3% -0.0%
=======================================
Files 442 442
Lines 22541 22543 +2
=======================================
- Hits 20350 20347 -3
- Misses 2191 2196 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Description
The
project_oauth_clientsFK onprojectswas created with the defaulton_delete: :nothing, andProjectHook.handle_delete_project/1never deletedthe join rows before calling
Repo.delete(project). So any project that hasan OAuth client attached fails to purge — the scheduled
purge_deletedObanjob crashes with a
project_oauth_clients_project_id_fkeyconstraint errorand the project is stuck in the soft-deleted state forever.
Fix is straightforward: clean up the join rows alongside the other
project-scoped deletes in
ProjectHook.handle_delete_project/1. The OAuthclient itself is not project-scoped so it's left alone.
Drive-by: also includes a small fix for a flaky
InstallAdaptorIconsTestwhere
Mix.shellwasn't being restored between tests.Validation steps
test/lightning/projects_test.exscovers it —insert a project with a
project_oauth_client, delete the project,assert the join row is gone and the OAuth client survives.
mix test test/lightning/projects_test.exs— all green.AI Usage
You can read more details in our
Responsible AI Policy
Pre-submission checklist
/reviewwith Claude Code)
(e.g.,
:owner,:admin,:editor,:viewer)