[Bug][ActiveRecord] Fix this (data loss?) bug in association assignment (has PR)

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[Bug][ActiveRecord] Fix this (data loss?) bug in association assignment (has PR)

Florian Ebeling
A while back I discovered a bug in `ActiveRecord::Associations::CollectionProxy#replace` and fixed it. See links to issue and PR below.  I think it can be called a data-loss issue, though it's unlikely to hit by surprise.

I created a reproducing test case (link also below), tried to follow contribution guidelines, and wrote a patch.

The problem is with assignment to has_many-through associations, when _also_ some occurrences are duplicate _and_ preexist.

The cause is a conceptually wrong use of `Array#-` which has set semantics, breaking down in the duplicate use case.

The rails-bot promised I should hear feedback shortly, but that didn't happen, yet. I do understand the constraints of Open Source and how they apply here.

I just edited, simplified, shortened and generally (hopefully) made the bug report and PR more compelling.

Also, rebased the PR just a few minutes ago.

I'd be very happy about some feedback from rails-core - on the change, and how it can be made acceptable for inclusion.

Have a nice Sunday!

Issue: https://github.com/rails/rails/issues/33942
Repro Test Case: https://gist.github.com/febeling/06e1da8ad34d5a9c45d41420efbe58bc
PR: https://github.com/rails/rails/pull/33954

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.