-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
@WIP Fixed bug where processing occurs on invalid objects #2594
base: master
Are you sure you want to change the base?
Conversation
@@ -807,6 +856,7 @@ def make; @file; end | |||
end | |||
|
|||
context "Assigning an attachment with post_process hooks" do | |||
# NOTE: Investigate the before_post_process hooks, as they may be intended to run on assignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [99/80]
it "doesn't call #make with attachment passed as third argument" do | ||
@dummy.avatar = @file | ||
|
||
expect(Paperclip::Test).not_to have_received(:make).with(anything, anything, @dummy.avatar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [99/80]
|
||
@dummy.avatar = @file | ||
|
||
expect(Paperclip::Thumbnail).not_to have_received(:make).with(anything, expected_params, anything) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [106/80]
whiny: true, | ||
convert_options: "", | ||
source_file_options: "" | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/IndentHash: Indent the right brace the same as the first position after the preceding left parenthesis.
processors: [:thumbnail, :test], | ||
whiny: true, | ||
convert_options: "", | ||
source_file_options: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
it 'does not process attachments given an invalid assignment with :not' do | ||
it 'processes attachments given a valid object' do | ||
file = File.new(fixture_file("5k.png")) | ||
Dummy.validates_attachment :avatar, content_type: {content_type: "image/png"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideHashLiteralBraces: Space inside { missing.
Metrics/LineLength: Line is too long. [83/80]
Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
@@ -57,24 +71,37 @@ | |||
attachment.assign(file) | |||
end | |||
|
|||
it 'does not process attachments given an invalid assignment with :not' do | |||
it 'processes attachments given a valid object' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end | ||
|
||
it 'does not process attachments given an invalid assignment with :content_type' do | ||
it 'does not process attachments given an invalid object with :content_type' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [83/80]
attachment.save | ||
end | ||
|
||
it 'does not process attachments given an invalid object with :not' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
|
||
attachment.assign(file) | ||
end | ||
|
||
it 'does not process attachments given an invalid assignment with :not' do | ||
it 'processes attachments given the object is valid' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@jrochkind @tute Perhaps I'm mistaken, but I believe all these problems are because the processors were being called on assignment, rather then during saving. Perhaps you can chime in and let me know if I'm missing something. I'm trying to fix tests that seem to assert incorrect behavior, and get this PR ready for merging (assuming my assumptions about the nature of the bug are correct). |
Sorry, it's been around 12 months since I last used paperclip, and I no longer work on the project where I encountered the issue I filed... it turns out almost exactly two years ago to this day. (anniversary, woo). |
@jrochkind no worries, thanks for all the work you previously did! |
Hi @saghaulor thank you for tracking down the cause of those bugs! We're looking to cut a few bugfix releases of Paperclip while people are transitioning to Rails 5.2's ActiveStore. My concern is that this bugfix will introduce unexpected behavior elsewhere. Do you know what kind of impact this will have on existing Paperclip uses? |
Are you saying you expect to retire Paperclip in light of ActiveStorage? I hadn't heard that. |
It's not official yet, just something we're working on. |
Thanks. Providing instructions for those who want to migrate to AS does not necessarily imply that you are sunsetting Paperclip, but sounds like you are strongly considering it, ok. |
@mike-burns I'm still trying to determine if there are any side effects. From cursory testing it seems that it will behave as one would expect. However, as I'm sure you're well aware, it's very difficult to account for the myriad of use cases users have concocted. It's sad to hear that Paperclip may be deprecated. From what I saw, ActiveStorage looks promising but is not a sufficient replacement for Paperclip. Moreover, migrating may be quite an undertaking if users have numerous models with attachments. Unless I'm mistaken, ActiveStorage doesn't offer the processor plugin framework nor the security mechanisms that Paperclip offer. Granted, some of these can be reimplemented as modules. |
Talked with @sidraval IRL. Let's do this:
We have concerns about this PR being a breaking change for some people who have worked around this bug. But we also want to see this bug fixed. Sound good, @saghaulor ? |
6.1 is out. Time to merge this. @saghaulor I'm getting some 61 test failures locally after rebasing with |
Sorry about the lack of movement. I've been traveling a lot recently. I'm
hoping to work on this and hopefully have it ready in the next couple of
weeks.
On Fri, Jul 27, 2018 at 4:20 PM Mike Burns ***@***.***> wrote:
6.1 is out. Time to merge this.
@saghaulor <https://github.com/saghaulor> I'm getting some 61 test
failures locally after rebasing with master. Do you have the bandwidth to
get these passing, or at least get it to a <20 number of failures?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2594 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAQtxjNCvEKRRWYXRtY9Mv7yg9w8EJ8eks5uK3YZgaJpZM4TmlJH>
.
--
Dutifully yours,
Stephen Aghaulor
|
Thank you! And I totally understand. |
- 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
90b2060
to
eaed2af
Compare
end | ||
|
||
it 'does not process attachments given an invalid assignment with :content_type' do | ||
it 'does not process attachments given an invalid object with :content_type' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [83/80]
attachment.save | ||
end | ||
|
||
it 'does not process attachments given an invalid object with :not' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@saghaulor This bug has been fixed in https://github.com/kreeti/kt-paperclip. |
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 Post processing callbacks are run on invalid attachments. #2462, Closes Conflict between README and Wiki on Post Processing. #2321, Closes
contradictory wiki / readme about preprocessing invalid too-large files #2236, Closes after_post_process is run even if validations fail #2178,
Closes Failing validations don't prevent post_processing callbacks #1960, Closes DRAFT toward fixing after_post_process is run even if validations fail #2204