Repository navigation
Fix workflow state removeAll() deleting records across all realms - #50381
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a realm-isolation bug in workflow state cleanup where removing a realm could delete WORKFLOW_STATE records belonging to other realms. It changes the JPA cleanup logic to delete only workflow-state rows whose workflow component no longer exists (i.e., orphaned state after realm/component cascade deletion) and adds an integration test to prevent regressions.
Changes:
- Update
JpaWorkflowStateProvider.removeAll()to delete orphaned workflow state via a subquery againstCOMPONENT. - Add an integration test that creates workflows/state in two realms, removes one realm, and verifies the other realm’s state remains.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
model/jpa/src/main/java/org/keycloak/models/workflow/JpaWorkflowStateProvider.java |
Changes removeAll() from unconditional delete to orphan-only cleanup using a NOT IN (subquery) against workflow components. |
tests/base/src/test/java/org/keycloak/tests/workflow/WorkflowManagementTest.java |
Adds a regression test covering realm removal behavior with workflow state across two realms. |
Comment on lines
+214
to
+218
| // this method is called after the realm entity has been removed and its component records | ||
| // (including workflows) have been cascade-deleted. Use a NOT IN subquery to delete workflow | ||
| // state entries whose workflow no longer exists. | ||
| Subquery<String> existingWorkflowIds = delete.subquery(String.class); | ||
| Root<ComponentEntity> component = existingWorkflowIds.from(ComponentEntity.class); |
Comment on lines
+696
to
+700
| RealmRepresentation realmBRep = new RealmRepresentation(); | ||
| realmBRep.setRealm("realm-b-test"); | ||
| realmBRep.setEnabled(true); | ||
| bootstrapAdmin.realms().create(realmBRep); | ||
|
|
Comment on lines
+730
to
+732
| // delete realm B — this should only remove realm B's workflow state | ||
| bootstrapAdmin.realm("realm-b-test").remove(); | ||
| } catch (Exception e) { |
pedroigor
approved these changes
Jun 29, 2026
Closes keycloak#50380 Signed-off-by: Stefan Guilhen <[email protected]>
pedroigor
force-pushed
the
50380-workflows-removeall
branch
from
June 29, 2026 13:42
230797f to
4d72e6e
Compare
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.
Closes #50380