@@ -315,9 +315,9 @@ func (s *Persistence) GetActor(ctx context.Context, atespace, id string) (*ateap
315315 return nil , fmt .Errorf ("while unmarshaling actor: %w" , err )
316316 }
317317
318- if actor . GetActorId () != id || actor . GetAtespace () != atespace {
319- return nil , fmt . Errorf ( "(impossible) mismatch between stored id/ atespace and key" )
320- }
318+ // Identity lives in the key, not the value.
319+ actor . Atespace = atespace
320+ actor . ActorId = id
321321
322322 return actor , nil
323323}
@@ -329,6 +329,9 @@ func (s *Persistence) CreateActor(ctx context.Context, actor *ateapipb.Actor) er
329329 // stomp the caller's copy.
330330 dbActor := proto .Clone (actor ).(* ateapipb.Actor )
331331 dbActor .Version = 1
332+ // Clear the identity as they are stored in key instead of value.
333+ dbActor .Atespace = ""
334+ dbActor .ActorId = ""
332335
333336 dbActorBytes , err := protojson .Marshal (dbActor )
334337 if err != nil {
@@ -510,6 +513,9 @@ func (s *Persistence) UpdateActor(ctx context.Context, actor *ateapipb.Actor, ex
510513 // Clone because we will update the version field, and we don't want to
511514 // stomp the caller's copy.
512515 dbActor := proto .Clone (actor ).(* ateapipb.Actor )
516+ // Clear the identity as they are stored in key instead of value.
517+ dbActor .Atespace = ""
518+ dbActor .ActorId = ""
513519
514520 err := s .rdb .Watch (ctx , func (tx * redis.Tx ) error {
515521 currentVal , err := tx .Get (ctx , dbKey ).Bytes ()
@@ -529,12 +535,6 @@ func (s *Persistence) UpdateActor(ctx context.Context, actor *ateapipb.Actor, ex
529535 return store .ErrPersistenceRetry
530536 }
531537 dbActor .Version = currentActor .GetVersion () + 1
532- if currentActor .GetActorId () != dbActor .GetActorId () {
533- return fmt .Errorf ("actor_id is immutable" )
534- }
535- if currentActor .GetAtespace () != dbActor .GetAtespace () {
536- return fmt .Errorf ("atespace is immutable" )
537- }
538538 if currentActor .GetActorTemplateNamespace () != dbActor .GetActorTemplateNamespace () {
539539 return fmt .Errorf ("actor_template_namespace is immutable" )
540540 }
@@ -755,7 +755,7 @@ func (s *Persistence) fetchActors(ctx context.Context, master *redis.Client, key
755755 }
756756
757757 var actors []* ateapipb.Actor
758- for _ , cmd := range cmds {
758+ for i , cmd := range cmds {
759759 getCmd , ok := cmd .(* redis.StringCmd )
760760 if ! ok {
761761 continue
@@ -771,6 +771,13 @@ func (s *Persistence) fetchActors(ctx context.Context, master *redis.Client, key
771771 if err := protojson .Unmarshal ([]byte (getCmd .Val ()), actor ); err != nil {
772772 return nil , fmt .Errorf ("in protojson.Unmarshal: %w" , err )
773773 }
774+ // Identity lives in the key, not the value.
775+ parts := strings .Split (keys [i ], ":" )
776+ if len (parts ) != 3 {
777+ return nil , fmt .Errorf ("bad key format %q" , keys [i ])
778+ }
779+ actor .Atespace = parts [1 ]
780+ actor .ActorId = parts [2 ]
774781 actors = append (actors , actor )
775782 }
776783 return actors , nil
0 commit comments