From c0b2aae84ebcacbe77046fc7ba8870df7e7d44c8 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 13 Apr 2022 18:50:33 +0530 Subject: [PATCH] MM-43340: Fix racy test TestGraphQLChannelMembers (#19968) We take a shallow copy of the team pointer before we pass that to the other functions. This is because the resolvers run in separate goroutines. https://mattermost.atlassian.net/browse/MM-43340 ```release-note NONE ``` --- api4/resolver_team.go | 1 + model/team.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/api4/resolver_team.go b/api4/resolver_team.go index 07d911d47f..be46bbed89 100644 --- a/api4/resolver_team.go +++ b/api4/resolver_team.go @@ -30,6 +30,7 @@ func getGraphQLTeam(ctx context.Context, id string) (*model.Team, error) { return nil, err } team := result.(*model.Team) + team = team.ShallowCopy() if (!team.AllowOpenInvite || team.Type != model.TeamOpen) && !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), team.Id, model.PermissionViewTeam) { diff --git a/model/team.go b/model/team.go index 7a21ffc790..92b6f7fc5a 100644 --- a/model/team.go +++ b/model/team.go @@ -252,6 +252,12 @@ func (o *Team) IsGroupConstrained() bool { return o.GroupConstrained != nil && *o.GroupConstrained } +// ShallowCopy returns a shallow copy of team. +func (o *Team) ShallowCopy() *Team { + c := *o + return &c +} + // The following are some GraphQL methods necessary to return the // data in float64 type. The spec doesn't support 64 bit integers, // so we have to pass the data in float64. The _ at the end is