Skip to content

fix: do not roll back transaction on partial identity insert error#5

Open
amartinj wants to merge 3 commits into
goodnotesfrom
MNA-4808-fix-identity-persist
Open

fix: do not roll back transaction on partial identity insert error#5
amartinj wants to merge 3 commits into
goodnotesfrom
MNA-4808-fix-identity-persist

Conversation

@amartinj

@amartinj amartinj commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Backport of upstream fix ory/kratos#4211 onto our goodnotes branch.

Problem

When CreateIdentities is called with a batch that contains conflicts, Kratos assigns UUIDs to identities and writes them to the accounts DB, but the identities are never persisted in Kratos's own DB. This leaves users in an inconsistent state — they exist in the accounts DB but cannot authenticate.

Root cause: partialErr was returned from inside the Transaction() callback. Since Transaction() rolls back on any non-nil error return, even the successfully-created identities get rolled back and never committed.

Fix

Cherry-pick of upstream commit 82660f04e:

  • persistence/sql/identity/persister_identity.go: declare partialErr outside the transaction, return nil from the callback (so successful identities are committed), return partialErr.ErrOrNil() after the transaction.
  • identity/manager.go: add NewCreateIdentitiesError() constructor; fix ErrOrNil() to handle nil receiver.

Checklist

  • I have added tests that prove my fix is effective or that my feature works.

@noells noells left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants