rubysherpas / paranoia

acts_as_paranoid for Rails 5, 6 and 7
Other
2.87k stars 524 forks source link

`destroy` doesn't work with the new version of Rails 7.0.6 #544

Closed VitaliSakolski closed 10 months ago

VitaliSakolski commented 1 year ago

When I tried to upgrade to the latest version of Rails 7.0.6, the tests started crashing. What was my surprise when after investigating it turned out that destroy doesn't work. In fact, everything is in the screenshots below:

Screenshot at Jul 04 18-29-06 Screenshot at Jul 04 18-31-09 Screenshot at Jul 04 19-07-03
dcrec1 commented 1 year ago

I have an issue related to this. In my case, for example record.destroy returns false, but the deleted_at column is updated.

mathieujobin commented 1 year ago

Thanks for reporting it. I don't know what would be causing it... 7.0.6 diff is pretty thin from 7.0.5

Stashchenko commented 11 months ago

Thanks for reporting it. I don't know what would be causing it... 7.0.6 diff is pretty thin from 7.0.5

The same issue on the rails 7.0.7

mathieujobin commented 11 months ago

I'm sorry, I am unable to come up with a patch at the moment, but if someone is willing to fix this and open a pull request, I can review and release.

Thanks

mjobin-mdsol commented 11 months ago

can you try this https://github.com/rubysherpas/paranoia/pull/545 and let us know ?

Stashchenko commented 10 months ago

can you try this #545 and let us know ?

Ok, will let you know about results

UPD: Nope, does not work :(

VitaliSakolski commented 10 months ago

can you try this #545 and let us know ?

Just tried this solution - still doesn't work

mathieujobin commented 10 months ago
(byebug) subject
#<CostCenter id: 3, name: "Human Resources", account_id: 98, created_at: "2023-08-30 23:20:07.000000000 +0000", 
updated_at: "2023-08-30 23:20:07.000000000 +0000", deleted_at: nil>
(byebug) subject.destroy
#<CostCenter id: 3, name: "Human Resources", account_id: 98, created_at: "2023-08-30 23:20:07.000000000 +0000", 
updated_at: "2023-08-30 23:20:15.000000000 +0000", deleted_at: "2023-08-30 23:20:15.000000000 +0000">
(byebug) subject.reload
#<CostCenter id: 3, name: "Human Resources", account_id: 98, created_at: "2023-08-30 23:20:07.000000000 +0000", 
updated_at: "2023-08-30 23:20:15.000000000 +0000", deleted_at: "2023-08-30 23:20:15.000000000 +0000">

(byebug) CostCenter.where(id: 3)
#<ActiveRecord::Relation []>
(byebug) CostCenter.count 
2
(byebug) subject = CostCenter.where(id: 2).take 
#<CostCenter id: 2, name: "different name", account_id: 97, created_at: "2023-08-30 23:20:06.000000000 +0000", 
updated_at: "2023-08-30 23:20:06.000000000 +0000", deleted_at: nil>
(byebug) subject.destroy
#<CostCenter id: 2, name: "different name", account_id: 97, created_at: "2023-08-30 23:20:06.000000000 +0000", 
updated_at: "2023-08-30 23:21:35.000000000 +0000", deleted_at: "2023-08-30 23:21:35.000000000 +0000">
(byebug) CostCenter.count 
1
(byebug) CostCenter.find_by_sql('select * from cost_centers where deleted_at is not null')
[#<CostCenter id: 3, name: "Human Resources", account_id: 98, created_at: "2023-08-30 23:20:07.000000000 +0000", 

updated_at: "2023-08-30 23:20:15.000000000 +0000", deleted_at: "2023-08-30 23:20:15.000000000 +0000">, 
#<CostCenter id: 2, name: "different name", account_id: 97, created_at: "2023-08-30 23:20:06.000000000 +0000", 

updated_at: "2023-08-30 23:21:35.000000000 +0000", deleted_at: "2023-08-30 23:21:35.000000000 +0000">]
(byebug) 

what is wrong ?

VitaliSakolski commented 10 months ago

what is wrong ?

Where am I wrong?

Gemfile:

Screenshot at Aug 31 10-58-55

Result:

Screenshot_at_Aug_31_10-49-33(1)

UPD:

Upon further investigation, the following issue was identified. Due to the specifics, we were using the before_destroy callback, which caused the above issue despite the patch. After replacing it with after_destroy everything started working as expected.

mathieujobin commented 10 months ago

I am also unsure what you use a fork version... Happy to hear you found the bug.

$ grep paranoia Gemfile*
Gemfile:gem 'paranoia'
Gemfile.lock:    paranoia (2.6.2)
Gemfile.lock:  paranoia