Repository navigation
Fix upgrade failure when existing OAuth2 tokens hit oauth2_provider 0012 before main 0198 - #1185
Closed
ssimpson89 wants to merge 2 commits into
Closed
ssimpson89 wants to merge 2 commits into
ssimpson89 wants to merge 2 commits into
Conversation
…fill Signed-off-by: Stephen Simpson <ssimpson89@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The migration-ordering test fails under the API suite’s --nomigrations setting because the loader cannot find oauth2_provider.0012_add_token_checksum, causing NodeNotFoundError instead of validating ordering.
1 open issue
What changed in this PR
This PR fixes OAuth2 token upgrade failures by ensuring Ascender adds the token checksum field before the OAuth provider migration attempts to backfill it.
Changes:
- Adds an explicit migration ordering constraint to
main.0198. - Adds a regression test asserting that ordering in Django’s migration graph.
| File | Description |
|---|---|
ascender/main/tests/functional/test_migrations.py |
Adds a migration-order regression test. |
ascender/main/migrations/0198_oauth2accesstoken_token_checksum_and_more.py |
Orders checksum field creation before the OAuth provider backfill. |
Review effort: Balanced
…ed without connection Signed-off-by: Stephen Simpson <ssimpson89@users.noreply.github.com>
Collaborator
|
Duplicate of #1151 ? |
Contributor
Author
|
@cigamit yep, looks like it! I'll close this |
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.

SUMMARY
Upgrading from a pre-25.6 release to 25.6.x fails during the migration Job when the database has any existing OAuth2 access tokens:
The access token model is swapped to
main.OAuth2AccessToken, so the backfill inoauth2_provider.0012_add_token_checksumloads our model and callssave(update_fields=['token_checksum'])on every existing token. Thetoken_checksumcolumn on our model is added bymain.0198_oauth2accesstoken_token_checksum_and_more, but nothing in the graph orders0198ahead of0012. Django can schedule0012first, and when it does, the field is not in the historical model state yet. Fresh installs pass because the loop has no rows to save, so this only shows up on upgrades (or restores followed bymigrate) with existing tokens.The fix adds
run_before = [('oauth2_provider', '0012_add_token_checksum')]tomain.0198, the same approachmain.0025already uses foroauth2_provider.0001_initial. A test asserts thatmain.0198is in the forwards plan ofoauth2_provider.0012.Design notes:
0012resolves tomain.__first__, and no main migration up to0197depends on an oauth2_provider migration past0005.InconsistentMigrationHistory. A failed upgrade like the one above leaves0012unapplied, so it also stays consistent.ghcr.io/ctrliq/ascender:25.6.3image ships django-oauth-toolkit 3.3.0, which still runs the save. The ordering fix makes the migration correct regardless of which toolkit version is installed.Testing:
ascender-app-migration-25.6.3failed atoauth2_provider.0012with the error above.migratein the 25.6.3 image with the patched0198.main.0198applied beforeoauth2_provider.0012, both succeeded, no unapplied migrations remained, and both tokens hadtoken_checksumpopulated.Workaround for affected installs until this ships:
ascender-manage migrate main 0198 --noinput, thenascender-manage migrate --noinput.ISSUE TYPE
COMPONENT NAME
ASCENDER VERSION