Update the query used for authorizations pruning to exclude all authorizations that still have tokens attached #2251
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.
Currently, permanent authorizations that are not valid and still have tokens attached are not excluded by the query used in
OpenIddict*AuthorizationStore.PruneAsync()
: it's not a problem at all for MongoDB (which isn't relational), but for the EF Core-based store, it's now problematic since recent versions use batched deletes by default: if a token is still attached to an authorization, an exception is thrown when the DB detects an authorization still has children entities attached.By changing the logic used in all the stores to always exclude authorizations (no matter the type) that still have tokens attached, this PR should greatly reduce that risk.
Related discussion: https://matrix.to/#/!DYBDMbtjENXaKIMiCN:gitter.im/$yOUcTNT72_AgmjK9vHKlg1kCpR776CsjDMLpWIIQYWA?via=gitter.im&via=matrix.org