ory/kratos

Cannot patch identity with op: 'test', 'copy', 'move'

fmiqbal opened this issue · 3 comments

Preflight checklist

Ory Network Project

No response

Describe the bug

As per API docs on https://www.ory.sh/docs/kratos/reference/api#tag/identity/operation/patchIdentity, there is list of jsonpatch available op, stated as

The operation to be performed. One of "add", "remove", "replace", "move", "copy", or "test".

But I can't actually do "move", "copy", or "test",
just borrowing from https://jsonpatch.com/

curl --location --request PATCH 'http://localhost:4434/admin/identities/a04e0bf8-fb7f-463a-a567-be345458df0c' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '[
{ "op": "move", "from": "/biscuits/0", "path": "/best_biscuit" }
]'

response

{
    "error": {
        "code": 400,
        "status": "Bad Request",
        "reason": "An error occured when applying the JSON patch",
        "message": "unsupported operation: move"
    }
}

Looking at the code, the error thrown possibly from this

kratos/identity/handler.go

Lines 869 to 877 in 4f4394c

if err := jsonx.ApplyJSONPatch(requestBody, &patchedIdentity, "/id", "/stateChangedAt", "/credentials"); err != nil {
h.r.Writer().WriteError(w, r, errors.WithStack(
herodot.
ErrBadRequest.
WithReasonf("An error occured when applying the JSON patch").
WithErrorf("%v", err).
WithWrap(err),
))
return

and I notice that it use ory/x/jsonx, from which I found

https://github.com/ory/x/blob/52f7d778c2eea02e3e5bcf638c590c533127baa8/jsonx/patch.go#L17-L21

So at least for now I think the documentation is wrong

Reproducing the bug

From docker quickstart,

  1. create and identity
  2. do this curl
curl --location --request PATCH 'http://localhost:4434/admin/identities/a04e0bf8-fb7f-463a-a567-be345458df0c' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '[
{ "op": "move", "from": "/biscuits/0", "path": "/best_biscuit" }
]'

Relevant log output

No response

Relevant configuration

No response

Version

1.2.0

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Docker Compose

Additional Context

No response

Having the same issue.

What's the use case for using those operations? Isn't it easier and more stable to fetch the identity and then apply a replace operation?

I'm trying to migrate schemas with copy and move ops.
I need to rename some fields.
Trying to do that with Postman requests.
Without copy and move, I'll have to copy and paste values or write a client (migrator tool).