Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNIQUE constraint failure when updating identities via Admin API #325

Closed
jertel opened this issue Apr 8, 2020 · 0 comments · Fixed by #604
Closed

UNIQUE constraint failure when updating identities via Admin API #325

jertel opened this issue Apr 8, 2020 · 0 comments · Fixed by #604
Assignees
Labels
bug Something is not working.

Comments

@jertel
Copy link
Contributor

jertel commented Apr 8, 2020

Kratos responds with a 409 unique constraint violation when updating an identity via the admin API: PUT /identities/{id}. The first identity to be updated in this way will succeed. However, the next identity to be updated will fail with the following error:

 UNIQUE constraint failed: identity_verifiable_addresses.code

The first update always works, resulting in a blank code column in the above mentioned table. Subsequent updates to an alternate identity fail because they are also trying to put a blank code value into their row, which violates the unique constraint.

Steps to reproduce the behavior:

  1. On a clean Kratos quickstart install with default config, register two identities, A and B.
  2. Issue a PUT /identities/{A-id} request and observe a successful response.
  3. Issue a PUT /identities/{B-id} request and observe a 409 response.
kratos_1                      | time="2020-04-08T11:56:20Z" level=info msg="started handling request" method=PUT name="admin#http://kratos:4434/" remote="172.18.0.1:38762" request=/identities/e7ff8522-774a-4644-95af-3fb955e2a7ce
kratos_1                      | time="2020-04-08T11:56:20Z" level=error msg="An error occurred while handling a request" code=409 debug= details="map[]" error="sqlite create: UNIQUE constraint failed: identity_verifiable_addresses.code: Unable to insert or update resource because a resource with that value exists already" reason= request-id= status=409 trace="Stack trace: \ngithub.com/ory/x/sqlcon.HandleError\n\t/go/pkg/mod/github.com/ory/x@v0.0.95/sqlcon/error.go:60\ngithub.com/ory/kratos/persistence/sql.(*Persister).UpdateIdentity\n\t/home/ory/persistence/sql/persister_identity.go:188\ngithub.com/ory/kratos/identity.(*Manager).Update\n\t/home/ory/identity/manager.go:75\ngithub.com/ory/kratos/identity.(*Handler).update\n\t/home/ory/identity/handler.go:251\ngithub.com/julienschmidt/httprouter.(*Router).ServeHTTP\n\t/go/pkg/mod/github.com/julienschmidt/httprouter@v1.2.0/router.go:334\ngithub.com/urfave/negroni.Wrap.func1\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:46\ngithub.com/urfave/negroni.HandlerFunc.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:29\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/ory/x/metricsx.(*Service).ServeHTTP\n\t/go/pkg/mod/github.com/ory/x@v0.0.95/metricsx/middleware.go:261\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/ory/x/reqlog.(*Middleware).ServeHTTP\n\t/go/pkg/mod/github.com/ory/x@v0.0.95/reqlog/middleware.go:140\ngithub.com/urfave/negroni.middleware.ServeHTTP\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:38\ngithub.com/urfave/negroni.(*Negroni).ServeHTTP\n\t/go/pkg/mod/github.com/urfave/negroni@v1.0.0/negroni.go:96\ngithub.com/gorilla/context.ClearHandler.func1\n\t/go/pkg/mod/github.com/gorilla/context@v1.1.1/context.go:141\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2007\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2802\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1890\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_amd64.s:1357" writer=JSON
kratos_1                      | time="2020-04-08T11:56:20Z" level=info msg="completed handling request" method=PUT name="admin#http://kratos:4434/" remote="172.18.0.1:38762" request=/identities/e7ff8522-774a-4644-95af-3fb955e2a7ce status=409 text_status=Conflict took=2.562737ms

Expected Behavior:

The second PUT request should have succeeded.

@jertel jertel changed the title UNIQUE constraint violation when updating identities via Admin API UNIQUE constraint failure when updating identities via Admin API Apr 8, 2020
@aeneasr aeneasr added this to the v0.4.0-alpha.1 milestone Apr 29, 2020
@aeneasr aeneasr added the bug Something is not working. label Jun 10, 2020
@aeneasr aeneasr added this to To do in Maintainer's Board via automation Jun 10, 2020
@aeneasr aeneasr self-assigned this Jun 10, 2020
aeneasr added a commit that referenced this issue Jul 27, 2020
Maintainer's Board automation moved this from To do to Done Jul 27, 2020
aeneasr added a commit that referenced this issue Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working.
Projects
Development

Successfully merging a pull request may close this issue.

2 participants