Skip to content

ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection: Cannot modify association 'MergeRequest#suggestions' because the source reflection class 'Suggest...

https://sentry.gitlab.net/gitlab/gitlabcom/issues/857576/

ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection: Cannot modify association 'MergeRequest#suggestions' because the source reflection class 'Suggestion' is associated to 'Note' via :has_many.
  active_record/associations/through_association.rb:94:in `ensure_mutable'
    raise HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(owner, reflection)
  active_record/associations/has_many_through_association.rb:58:in `build_through_record'
    ensure_mutable
  active_record/associations/has_many_through_association.rb:31:in `block in concat_records'
    build_through_record(record)
  active_record/associations/has_many_through_association.rb:30:in `each'
    records.flatten.each do |record|
  active_record/associations/has_many_through_association.rb:30:in `concat_records'
    records.flatten.each do |record|
...
(106 additional frame(s) were not displayed)

ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection: Cannot modify association 'MergeRequest#suggestions' because the source reflection class 'Suggestion' is associated to 'Note' via :has_many.

Workaround

If you search your project.json file for "suggestions" then you would remove the entire suggestion, but as Stan pointed out, you can use jq to assist as per https://gitlab.com/gitlab-org/gitlab-ee/issues/12400#note_186060085

If you're exporting from a self-managed instance though, the easier fix (especially if you have multiple projects) would be to edit your import_export.yml (which you can find under gitlab/import_export/) as per https://gitlab.com/gitlab-org/gitlab-ce/issues/65880#note_202289565 or you can remove suggestions from the export altogether.

Edited by Cynthia "Arty" Ng