-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When reviving dependent associations, query is not scoped to parent record #75
Comments
That's definitely not the way it was intended! If you could put together a failing tests case for this all of the project members here would be much obliged, I'm sure. Thank you, @masonhale! |
@JackDanger I opened a PR #76 with a test spec that fails in the 3.2.0 release against activerecord 3.2 and activerecord 4.2. (The app I'm working with is still Rails 3.2). However the spec does not fail against the master branch. I see the master branch gemspec requires activerecord >= 4.2.0 so I am unable to test against activerecord 3.2. Is the 3.2.0 release the last one expected to support activerecord 3.2? |
The official releases are the ones on Rubygems.org: https://rubygems.org/gems/permanent_records At some point the ActiveRecord source changed so significantly that we stopped supporting 3.x. So it looks like what you've found is a great candidate for backporting. Maybe start at ad58da2 (the last commit of the 3.3.x releases of permanent_records) and apply your test and your fix there? Then we can issue a 3.3.1 backported fix with your changes that everybody can use on Rails 3.x.
Thanks for digging into this! My apps at Square have all been upgraded to 4.x (thank goodness) so I hadn't noticed this problem. |
I pulled down ad58da2 and merged the test spec I wrote into it, but I'm getting lots and lots of test failures related to 'destroy' returning false in some instances. A sample of the error I see (again and again)
I checked and loads of tests fail in ad58da2 before I merge my changes too (so my changes did not trigger the error). Rather than me tracking down the fix for this new error, I'm hoping you know the cause and hopefully the commit that fixes it? Are you sure this is the last commit before the 3.3.0 release? |
I do know the source of that error. I'll look at it tomorrow. Thanks for ::Jack On Mon, Jun 6, 2016 at 5:11 PM, Mason Hale [email protected] wrote:
|
On your branch you'll probably need to remove references to Rails 4+ in PermanentRecords has added a fix for the modern ActiveRecord API in a20e0f0 but I think you may not need that if you're building a fix for 3.x users. |
I was just debugging an issue when trying to revive a deleted record, and I found that that when reviving the dependent associations for the record, the query is not scoped to the parent record. By that I mean the query does not include the foreign key. Rather it merely looks for any record of the given type that happened to be deleted within the timeframe of the deleted_at (plus/minus the depended_record_window).
The result is that completely unrelated records could be revived if they happened to be deleted around the same time (something quite likely on a high traffic app). Surely this isn't the way it is meant to work is it?
My expectation is that query generated by
add_record_window
method would include the foreign_key of the containing record. See: https://github.com/JackDanger/permanent_records/blob/master/lib/permanent_records.rb#L134-L144I can try to create a patch for this issue, but first I would like to know if this is working 'as designed' if there is not reason the foreign key is not included?
The text was updated successfully, but these errors were encountered: