jhawthorn / discard

🃏🗑 Soft deletes for ActiveRecord done right

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bang-Methods hides internal errors (e.g. ActiveModel::ValidationError)

psmandzich opened this issue · comments

Describe the bug
Current implementation hides internal errors while discarding or undiscarding a record with bang method (e.g. ActiveModel::ValidationError).

To Reproduce
Steps to reproduce the behavior:

  1. Create model with validation
  2. Manipulate record of model without callbacks such that persisted data is invalid
  3. Call discard!

Expected behavior
Return exception should contain information about the concrete error.

Additional context
The Bug could be fixed by replacing the implementation of discard! with the content of discard. In that case update_attribute has to be replaced by update_attribute!. To achieve a non-breaking change, thrown exception can be attached to Discard Error classes. Same for undiscard!
If help is wanted, I'll submit a PR.

It's not hiding an internal error. None of the discard/undiscard methods care about validations. This mirrors the behaviour of methods like delete and destroy.

Closing because this behaviour is intentional.


If you need to soft-delete records in a way that respect validations, you can implement your own method or override the discard method with one that does the same thing as the discard method, but uses update rather than update_attribute.