GORM Playground Link

https://github.com/go-gorm/playground/pull/534

Description

I tried appending to a m2m association inside a concurrent goroutines and for some reason it appended only some of the data. While creating a minimal code example to test this i narrowed it down to this: - When the model is fetched from the db(previously created) & the associations are preloaded(Preload(clause.Associations)), it fails. - If any of this changes the test passes(note the comments in the code)

Comment From: a631807682

https://github.com/go-gorm/playground/pull/534/files#diff-79ce3229c13921b79b1175dcb211336aaf84dfd8edcf19c07698934d4fe70e5eR47

This error seems to be a race caused by userCopy.Languages even though each userCopy is different. I haven't found the bug, but this avoids it.

+ uuserCopy.Languages = nil
err := DB.Model(&userCopy).Association("Languages").Append(&languageCopy)