NokiaTube | New address | Mode Desktop | Off high quality for Nokia Browser
Skip to content

Fix workflow state removeAll() deleting records across all realms - #50381

Merged
pedroigor merged 1 commit into
keycloak:mainfrom
sguilhen:50380-workflows-removeall
Jun 29, 2026
Merged

pedroigor merged 1 commit into
keycloak:mainfrom
sguilhen:50380-workflows-removeall

Conversation

@sguilhen

Copy link
Copy Markdown
Contributor

Closes #50380

@sguilhen
sguilhen requested a review from a team as a code owner June 26, 2026 20:21
Copilot AI review requested due to automatic review settings June 26, 2026 20:21
@sguilhen
sguilhen requested a review from pedroigor June 26, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 against COMPONENT.
  • 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
pedroigor force-pushed the 50380-workflows-removeall branch from 230797f to 4d72e6e Compare June 29, 2026 13:42
@pedroigor
pedroigor merged commit 5210fbb into keycloak:main Jun 29, 2026
89 checks passed
@sguilhen
sguilhen deleted the 50380-workflows-removeall branch August 4, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workflow state removeAll() deletes records across all realms on realm removal

3 participants