Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

@WIP Fixed bug where processing occurs on invalid objects #2594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saghaulor
Copy link

@@ -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

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)

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)

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: ""
})

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: ""

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"}

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

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

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

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

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
Copy link
Author

@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).

@jrochkind
Copy link

jrochkind commented Apr 26, 2018

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).

@saghaulor
Copy link
Author

@jrochkind no worries, thanks for all the work you previously did!

@mike-burns
Copy link
Contributor

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?

@jrochkind
Copy link

We're looking to cut a few bugfix releases of Paperclip while people are transitioning to Rails 5.2's ActiveStore.

Are you saying you expect to retire Paperclip in light of ActiveStorage? I hadn't heard that.

@mike-burns
Copy link
Contributor

I hadn't heard that.

It's not official yet, just something we're working on.

@jrochkind
Copy link

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.

@saghaulor
Copy link
Author

@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.

@mike-burns
Copy link
Contributor

Talked with @sidraval IRL. Let's do this:

  • 6.1 with everything that's in master now.
  • 7.0 with this commit merged.
  • 7.1 with a deprecation notice across all of Paperclip.

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 ?

@mike-burns
Copy link
Contributor

6.1 is out. Time to merge this.

@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?

@saghaulor
Copy link
Author

saghaulor commented Jul 27, 2018 via email

@mike-burns
Copy link
Contributor

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
@saghaulor saghaulor force-pushed the processor_validation_fix branch from 90b2060 to eaed2af Compare August 19, 2018 01:04
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

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

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.

@ssinghi
Copy link

ssinghi commented Aug 6, 2020

@saghaulor This bug has been fixed in https://github.com/kreeti/kt-paperclip.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
6 participants