Skip to content
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

Rails 4.1 really_destroy! soft deletes the record #129

Closed
masterkain opened this issue Apr 13, 2014 · 12 comments
Closed

Rails 4.1 really_destroy! soft deletes the record #129

masterkain opened this issue Apr 13, 2014 · 12 comments

Comments

@masterkain
Copy link

Perhaps I'm missing something, however some of my test started failing.

I use paranoia master rails4 branch, I saw really_deleted! and tried to give it a go, unfortunately it seems that on Rails 4.1.0 (4-1-stable) doing so just soft deletes the record, that is, it sets the deleted_at value.

not sure if it helps but here's the debug trace:

=> 145:       destroy!
   146:     end
   147: 
   148:     include Paranoia
   149:     class_attribute :paranoia_column

(byebug) step

[58, 67] in /Users/kain/.rvm/gems/ruby-2.1.1/bundler/gems/paranoia-d657443970a8/lib/paranoia.rb
   58:   # unless you touch the paranoia column before.
   59:   # We need to override it here otherwise children records might be removed
   60:   # when they shouldn't
   61:   if ActiveRecord::VERSION::STRING >= "4.1"
   62:     def destroy!
=> 63:       destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
   64:     end
   65:   end
   66: 
   67:   def delete

(byebug) destroyed?
false
(byebug) step

[78, 87] in /Users/kain/.rvm/gems/ruby-2.1.1/bundler/gems/paranoia-d657443970a8/lib/paranoia.rb
   78:     end
   79:   end
   80:   alias :restore :restore!
   81: 
   82:   def destroyed?
=> 83:     !!send(paranoia_column)
   84:   end
   85:   alias :deleted? :destroyed?
   86: 
   87:   private

(byebug) n
Next went up a frame because previous frame finished

[58, 67] in /Users/kain/.rvm/gems/ruby-2.1.1/bundler/gems/paranoia-d657443970a8/lib/paranoia.rb
   58:   # unless you touch the paranoia column before.
   59:   # We need to override it here otherwise children records might be removed
   60:   # when they shouldn't
   61:   if ActiveRecord::VERSION::STRING >= "4.1"
   62:     def destroy!
=> 63:       destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
   64:     end
   65:   end
   66: 
   67:   def delete

(byebug) s

[48, 57] in /Users/kain/.rvm/gems/ruby-2.1.1/bundler/gems/paranoia-d657443970a8/lib/paranoia.rb
   48:       end
   49:     end
   50:   end
   51: 
   52:   def destroy
=> 53:     callbacks_result = run_callbacks(:destroy) { touch_paranoia_column(true) }
   54:     callbacks_result ? self : false
   55:   end
   56: 
   57:   # As of Rails 4.1.0 +destroy!+ will no longer remove the record from the db

I tried running the paranoia tests locally, and so far just one, possibly not related failure that is also present on travis.

The test for really_destroy! passes in the test suite, I also verified the sql queries it is doing and they seems correct, although I believe I'm testing against 4.0.4.

@radar
Copy link
Collaborator

radar commented Apr 22, 2014

@masterkain Do you have an app that you can reproduce this issue in? That would be really helpful!

@srecnig
Copy link
Contributor

srecnig commented May 23, 2014

hi!
i'm having the same issue with rails 4.1.1. calling really_destroy! will only soft-delete the record, calling really_destroy! on an already soft-deleted record will actually delete it from the database.

i ran the test suite against rails 4.1.1 and the two tests that are checking really_destroy! are failing (along with two other tests (test_restore_with_nil_has_one_association & test_delete_behavior_for_plain_models_callbacks) that seem unrelated).

1) Failure:
ParanoiaTest#test_real_destroy_dependent_destroy [test/paranoia_test.rb:301]:
Failed refutation, no message given

3) Failure:
ParanoiaTest#test_really_destroy [test/paranoia_test.rb:294]:
Failed refutation, no message given

i looked through the code and saw the following method, which also seems to be the problem:

 # As of Rails 4.1.0 +destroy!+ will no longer remove the record from the db
 # unless you touch the paranoia column before.
 # We need to override it here otherwise children records might be removed
 # when they shouldn't
 if ActiveRecord::VERSION::STRING >= "4.1"
   def destroy!
     destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
   end
 end

so is this the expected behaviour with rails 4.1.x? do we have to touch the paranoia column before calling really_destroy! ?

@MarkMurphy
Copy link

I get the same error when calling the regular destroy! method

@matcouto
Copy link

Yep, same here.
paranoia (~> 2.0)
Rails 4.0.4
and the method really_destroy! still soft-deletes the record.

@radar
Copy link
Collaborator

radar commented Sep 29, 2014

@matcouto Please upgrade your Rails version. It is currently 6 steps behind the current Rails 4.0.x "HEAD".

@MarkMurphy
Copy link

@radar @masterkain I'm re-inventing paranoia here: https://github.com/MarkMurphy/paranoia/tree/3.0-wip

All I have left to do is re-integrate the restore methods and write the unit tests.

Major differences are:

  • Less code
  • really_destroy! has been replaced by destroy!(force: true)
  • It works with Rails 4.1+
  • Code is much more modularized
  • Has it's own configuration class
  • Currently missing restore functionality
  • Currently missing unit tests

@radar
Copy link
Collaborator

radar commented Oct 11, 2014

@MarkMurphy Why on earth are you doing that? Why not contribute back to the main repo instead of forking? If you're that keen on building it yourself then I can add you as a contributor here.

@MarkMurphy
Copy link

@radar There's no reason it can't be turned into a pull request.

@zwippie
Copy link

zwippie commented Jan 6, 2015

Any updates on this issue? Still not working with Rails 4.1.6 in my case. Calling really_destroy! twice also does not solve the problem.

@stevegrossi
Copy link

For what it's worth, I'm using paranoia 2.2.1 and Rails 4.2 and both destroy! and really_destroy! are working as expected. So upgrading this gem and/or Rails may solve the issue.

@radar
Copy link
Collaborator

radar commented Apr 14, 2015

Please try using the latest Rails + paranoia gem releases and let me know if the issue is still occurring on those. I will assume this is fixed until I see proof otherwise

@radar radar closed this as completed Apr 14, 2015
@sumit-rvtech
Copy link

Hello,

I am getting the error below for inherited object:

NoMethodError: undefined method `paranoid_column' for #Class:0x00000003432aa8
Did you mean? paranoia_column
paranoia_column?
paranoia_column=
But when I include "acts_as_paranoid" to same inherited class then it really_destroy! not working. Its applying soft delete only not hard.I am using rails 5.0.2 and paranoia 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants