-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Failing validations don't prevent post_processing callbacks #1960
Failing validations don't prevent post_processing callbacks #1960
Comments
This sounds like a bug that should be addressed in a PR. @jyurek? |
Agreed, this is definitely a bug. @danielfone, thanks a huge amount for the runnable verification! |
Well, that's dumb. OK, on digging a little, I recalled that the validators are defined as before_post_process callbacks. So we can't simply ignore them. That being the case, what would be the expectation, here. Is simply documenting that |
From my limited point of view, here's 3 options:
IMO running the post_processing callbacks on an attachment that is obviously invalid is surprising behaviour. The fact that the validations are being run as |
Related with: #2178 |
- Because the processors were called on assignment, instead of during saving, the validations could never work correctly. This is because the built in validations use the values in the db columns to operate. However, since these are populated on assignment, the validations cannot run before the processors run. Moreover, any other type of validation not dependent on the db columns also cannot run, because the processors are called on assignment. The processors should be called during save which allows for validations to occur. - Fixed tests that assert the incorrect behavior - Closes thoughtbot#2462, Closes thoughtbot#2321, Closes thoughtbot#2236, Closes thoughtbot#2178, Closes thoughtbot#1960, Closes thoughtbot#2204
Thank you for reporting this. Unfortunately, we will be deprecating Paperclip and therefore will not have the bandwidth to address this issue. |
- Because the processors were called on assignment, instead of during saving, the validations could never work correctly. This is because the built in validations use the values in the db columns to operate. However, since these are populated on assignment, the validations cannot run before the processors run. Moreover, any other type of validation not dependent on the db columns also cannot run, because the processors are called on assignment. The processors should be called during save which allows for validations to occur. - Fixed tests that assert the incorrect behavior - Closes thoughtbot#2462, Closes thoughtbot#2321, Closes thoughtbot#2236, Closes thoughtbot#2178, Closes thoughtbot#1960, Closes thoughtbot#2204
This has been fixed at https://github.com/kreeti/paperclip/commits/master. |
Steps to Reproduce:
Expected:
As per the documentation in the README:
We would not expect the
after_post_process
callback to be run.Actual:
The code in attachment.rb will guard the post-processing against invalid attachments, but the callbacks will be run anyway.
I've setup a runnable, reproducible case here to demonstrate the issue in full.
Suggestion:
Either the README can be updated to reflect this behaviour, or the
Attachment#post_process
method could be rewritten not to run the callbacks when the validations fail. I'm more than happy to raise a PR depending on the preferred solution.The text was updated successfully, but these errors were encountered: