File tree 1 file changed +14
-10
lines changed
1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -16,21 +16,25 @@ const (
16
16
// own their own operations.
17
17
// Otherwise, the "owner" tag is always empty.
18
18
func MutateTags (userID uuid.UUID , tags map [string ]string ) map [string ]string {
19
- if tags == nil {
20
- tags = map [string ]string {}
19
+ // We copy the tags here to avoid overwriting the provided map. This can
20
+ // cause data races when using dbmem.
21
+ cp := map [string ]string {}
22
+ for k , v := range tags {
23
+ cp [k ] = v
21
24
}
22
- _ , ok := tags [TagScope ]
25
+
26
+ _ , ok := cp [TagScope ]
23
27
if ! ok {
24
- tags [TagScope ] = ScopeOrganization
25
- delete (tags , TagOwner )
28
+ cp [TagScope ] = ScopeOrganization
29
+ delete (cp , TagOwner )
26
30
}
27
- switch tags [TagScope ] {
31
+ switch cp [TagScope ] {
28
32
case ScopeUser :
29
- tags [TagOwner ] = userID .String ()
33
+ cp [TagOwner ] = userID .String ()
30
34
case ScopeOrganization :
31
- delete (tags , TagOwner )
35
+ delete (cp , TagOwner )
32
36
default :
33
- tags [TagScope ] = ScopeOrganization
37
+ cp [TagScope ] = ScopeOrganization
34
38
}
35
- return tags
39
+ return cp
36
40
}
You can’t perform that action at this time.
0 commit comments