Skip to content

Commit

Permalink
fix: explicity set updated_at field when updating identity (#4131)
Browse files Browse the repository at this point in the history
  • Loading branch information
maoanran authored Oct 3, 2024
1 parent 4f1a2b7 commit 66afac1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions identity/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,22 @@ func TestManager(t *testing.T) {
// That is why we only check the identity in the store.
checkExtensionFields(fromStore, "[email protected]")(t)
})

t.Run("case=should always update updated_at field", func(t *testing.T) {
original := identity.NewIdentity(config.DefaultIdentityTraitsSchemaID)
original.Traits = newTraits("[email protected]", "")
require.NoError(t, reg.IdentityManager().Create(ctx, original))

time.Sleep(time.Millisecond)

require.NoError(t, reg.IdentityManager().UpdateTraits(
ctx, original.ID, newTraits("[email protected]", ""),
identity.ManagerAllowWriteProtectedTraits))

updated, err := reg.IdentityPool().GetIdentity(ctx, original.ID, identity.ExpandNothing)
require.NoError(t, err)
assert.NotEqual(t, original.UpdatedAt, updated.UpdatedAt, "UpdatedAt field should be updated")
})
})

t.Run("method=RefreshAvailableAAL", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions persistence/sql/identity/persister_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ func (p *IdentityPersister) UpdateIdentity(ctx context.Context, i *identity.Iden
}

i.NID = p.NetworkID(ctx)
i.UpdatedAt = time.Now().UTC()
if err := sqlcon.HandleError(p.Transaction(ctx, func(ctx context.Context, tx *pop.Connection) error {
// This returns "ErrNoRows" if the identity does not exist
if err := update.Generic(WithTransaction(ctx, tx), tx, p.r.Tracer(ctx).Tracer(), i); err != nil {
Expand Down

0 comments on commit 66afac1

Please sign in to comment.