Skip to content

Client update changes it's PK to 0 #2148

@clement-buchart

Description

@clement-buchart

Describe the bug

In v1.9.0-aplha.1, it seems when updating a client, it's PK is set to 0.

I'm not familiar with the pop persistence layer, but maybe here cl does not have the PK, and it should be copied from o which is retrieved from the database, so the PK does not change on update :

func (p *Persister) UpdateClient(ctx context.Context, cl *client.Client) error {
return p.transaction(ctx, func(ctx context.Context, c *pop.Connection) error {
o, err := p.GetClient(ctx, cl.GetID())
if err != nil {
return err
}
if cl.Secret == "" {
cl.Secret = string(o.GetHashedSecret())
} else {
h, err := p.r.ClientHasher().Hash(ctx, []byte(cl.Secret))
if err != nil {
return errors.WithStack(err)
}
cl.Secret = string(h)
}
return sqlcon.HandleError(c.Update(cl))
})
}

Reproducing the bug

On a fresh hydra instance

  • Create 2 clients : they are given PK 1 and 2
  • Update one of the clients, it's PK changes to 0
  • Try to update the other -> duplicate key value violates unique constraint "hydra_client_pkey"

Server logs

duplicate key value violates unique constraint "hydra_client_pkey" 

Expected behavior

PK is not set to 0 on update

Environment

  • Version: v1.9.0-alpha.1

Additional context

I was using the alpha version by 'mistake' in a non-production environment, hope it's ok to report issue on an alpha.

Cheers.

Metadata

Metadata

Assignees

Labels

blockingBlocks milestones or other issues or pulls.bugSomething is not working.corp/m3Up for M3 at Ory Corp.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions