From f6260a00852946a10a57e8bb9f505f19bc9389b7 Mon Sep 17 00:00:00 2001 From: Artemij Shepelev Date: Sat, 22 Sep 2018 14:59:11 +0300 Subject: [PATCH] Second part of the defaultTableName field race fix (#2060) * fix (https://github.com/jinzhu/gorm/issues/1407) * changed map with mutex to sync.Map (https://github.com/jinzhu/gorm/issues/1407) * removed newModelStructsMap func * commit to rerun pipeline, comment changed * fix race with defaultTableName field (again) --- model_struct.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/model_struct.go b/model_struct.go index 12860e67..8c27e209 100644 --- a/model_struct.go +++ b/model_struct.go @@ -24,11 +24,16 @@ type ModelStruct struct { PrimaryFields []*StructField StructFields []*StructField ModelType reflect.Type + defaultTableName string + l sync.Mutex } // TableName returns model's table name func (s *ModelStruct) TableName(db *DB) string { + s.l.Lock() + defer s.l.Unlock() + if s.defaultTableName == "" && db != nil && s.ModelType != nil { // Set default table name if tabler, ok := reflect.New(s.ModelType).Interface().(tabler); ok {