@@ -580,6 +580,10 @@ func (q *FakeQuerier) getProvisionerJobByIDNoLock(_ context.Context, id uuid.UUI
580
580
if provisionerJob .ID != id {
581
581
continue
582
582
}
583
+ // clone the Tags before returning, since maps are reference types and
584
+ // we don't want the caller to be able to mutate the map we have inside
585
+ // dbmem!
586
+ provisionerJob .Tags = maps .Clone (provisionerJob .Tags )
583
587
return provisionerJob , nil
584
588
}
585
589
return database.ProvisionerJob {}, sql .ErrNoRows
@@ -779,6 +783,10 @@ func (q *FakeQuerier) AcquireProvisionerJob(_ context.Context, arg database.Acqu
779
783
provisionerJob .WorkerID = arg .WorkerID
780
784
provisionerJob .JobStatus = provisonerJobStatus (provisionerJob )
781
785
q .provisionerJobs [index ] = provisionerJob
786
+ // clone the Tags before returning, since maps are reference types and
787
+ // we don't want the caller to be able to mutate the map we have inside
788
+ // dbmem!
789
+ provisionerJob .Tags = maps .Clone (provisionerJob .Tags )
782
790
return provisionerJob , nil
783
791
}
784
792
return database.ProvisionerJob {}, sql .ErrNoRows
@@ -1884,6 +1892,10 @@ func (q *FakeQuerier) GetHungProvisionerJobs(_ context.Context, hungSince time.T
1884
1892
hungJobs := []database.ProvisionerJob {}
1885
1893
for _ , provisionerJob := range q .provisionerJobs {
1886
1894
if provisionerJob .StartedAt .Valid && ! provisionerJob .CompletedAt .Valid && provisionerJob .UpdatedAt .Before (hungSince ) {
1895
+ // clone the Tags before appending, since maps are reference types and
1896
+ // we don't want the caller to be able to mutate the map we have inside
1897
+ // dbmem!
1898
+ provisionerJob .Tags = maps .Clone (provisionerJob .Tags )
1887
1899
hungJobs = append (hungJobs , provisionerJob )
1888
1900
}
1889
1901
}
@@ -2191,7 +2203,15 @@ func (q *FakeQuerier) GetProvisionerDaemons(_ context.Context) ([]database.Provi
2191
2203
if len (q .provisionerDaemons ) == 0 {
2192
2204
return nil , sql .ErrNoRows
2193
2205
}
2194
- return q .provisionerDaemons , nil
2206
+ // copy the data so that the caller can't manipulate any data inside dbmem
2207
+ // after returning
2208
+ out := make ([]database.ProvisionerDaemon , len (q .provisionerDaemons ))
2209
+ copy (out , q .provisionerDaemons )
2210
+ for i := range out {
2211
+ // maps are reference types, so we need to clone them
2212
+ out [i ].Tags = maps .Clone (out [i ].Tags )
2213
+ }
2214
+ return out , nil
2195
2215
}
2196
2216
2197
2217
func (q * FakeQuerier ) GetProvisionerJobByID (ctx context.Context , id uuid.UUID ) (database.ProvisionerJob , error ) {
@@ -2209,6 +2229,10 @@ func (q *FakeQuerier) GetProvisionerJobsByIDs(_ context.Context, ids []uuid.UUID
2209
2229
for _ , job := range q .provisionerJobs {
2210
2230
for _ , id := range ids {
2211
2231
if id == job .ID {
2232
+ // clone the Tags before appending, since maps are reference types and
2233
+ // we don't want the caller to be able to mutate the map we have inside
2234
+ // dbmem!
2235
+ job .Tags = maps .Clone (job .Tags )
2212
2236
jobs = append (jobs , job )
2213
2237
break
2214
2238
}
@@ -2230,6 +2254,10 @@ func (q *FakeQuerier) GetProvisionerJobsByIDsWithQueuePosition(_ context.Context
2230
2254
for _ , job := range q .provisionerJobs {
2231
2255
for _ , id := range ids {
2232
2256
if id == job .ID {
2257
+ // clone the Tags before appending, since maps are reference types and
2258
+ // we don't want the caller to be able to mutate the map we have inside
2259
+ // dbmem!
2260
+ job .Tags = maps .Clone (job .Tags )
2233
2261
job := database.GetProvisionerJobsByIDsWithQueuePositionRow {
2234
2262
ProvisionerJob : job ,
2235
2263
}
@@ -2260,6 +2288,10 @@ func (q *FakeQuerier) GetProvisionerJobsCreatedAfter(_ context.Context, after ti
2260
2288
jobs := make ([]database.ProvisionerJob , 0 )
2261
2289
for _ , job := range q .provisionerJobs {
2262
2290
if job .CreatedAt .After (after ) {
2291
+ // clone the Tags before appending, since maps are reference types and
2292
+ // we don't want the caller to be able to mutate the map we have inside
2293
+ // dbmem!
2294
+ job .Tags = maps .Clone (job .Tags )
2263
2295
jobs = append (jobs , job )
2264
2296
}
2265
2297
}
@@ -4969,7 +5001,7 @@ func (q *FakeQuerier) InsertProvisionerJob(_ context.Context, arg database.Inser
4969
5001
FileID : arg .FileID ,
4970
5002
Type : arg .Type ,
4971
5003
Input : arg .Input ,
4972
- Tags : arg .Tags ,
5004
+ Tags : maps . Clone ( arg .Tags ) ,
4973
5005
TraceMetadata : arg .TraceMetadata ,
4974
5006
}
4975
5007
job .JobStatus = provisonerJobStatus (job )
@@ -6993,7 +7025,7 @@ func (q *FakeQuerier) UpsertProvisionerDaemon(_ context.Context, arg database.Up
6993
7025
continue
6994
7026
}
6995
7027
d .Provisioners = arg .Provisioners
6996
- d .Tags = arg .Tags
7028
+ d .Tags = maps . Clone ( arg .Tags )
6997
7029
d .Version = arg .Version
6998
7030
d .LastSeenAt = arg .LastSeenAt
6999
7031
return d , nil
@@ -7004,7 +7036,7 @@ func (q *FakeQuerier) UpsertProvisionerDaemon(_ context.Context, arg database.Up
7004
7036
CreatedAt : arg .CreatedAt ,
7005
7037
Name : arg .Name ,
7006
7038
Provisioners : arg .Provisioners ,
7007
- Tags : arg .Tags ,
7039
+ Tags : maps . Clone ( arg .Tags ) ,
7008
7040
ReplicaID : uuid.NullUUID {},
7009
7041
LastSeenAt : arg .LastSeenAt ,
7010
7042
Version : arg .Version ,
0 commit comments