Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: uploads:fix_missing_s3 rake task used wrong SHA1 #12495

Merged
merged 1 commit into from
Mar 25, 2021

Conversation

gschlager
Copy link
Member

No description provided.

@SamSaffron
Copy link
Member

not following here, upload did not change between the 2 lines, is sha being updated somewhere as a side effect?

@gschlager
Copy link
Member Author

gschlager commented Mar 23, 2021

Yeah, it must be a side effect. Sorry, I got confused... I'll get to the bottom of this tomorrow...

@gschlager
Copy link
Member Author

@SamSaffron I took another look and my initial suspicion was right after all, but I refactored my original PR into a one-liner.

Here's a simple demo of the problem:

ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)

id = Upload.last.id
upload = Upload.find(id)
original_sha1 = upload.sha1

Upload.transaction do
  upload.update!(sha1: SecureRandom.hex)
  raise ActiveRecord::Rollback
end

puts Upload.find(id).sha1
upload.update!(verification_status: 0)
puts Upload.find(id).sha1

upload.update!(sha1: original_sha1)

And here's the relevant log output:

   (0.0ms)  BEGIN
  Upload Update (0.4ms)  UPDATE "uploads" SET "sha1" = 'b3f67e355ddb366071ee8e088277194d', "updated_at" = '2021-03-24 14:31:05.380205' WHERE "uploads"."id" = 2
   (0.1ms)  ROLLBACK
  Upload Load (0.2ms)  SELECT * WHERE "uploads"."id" = 2 LIMIT 1
33dcda0dcceab8e1f8a4c6a9617a6c79ae0ddd1a
   (0.0ms)  BEGIN
  Upload Update (0.2ms)  UPDATE "uploads" SET "sha1" = 'b3f67e355ddb366071ee8e088277194d', "updated_at" = '2021-03-24 14:31:05.380205' WHERE "uploads"."id" = 2
   (8.1ms)  COMMIT
  Upload Load (0.2ms)  SELECT * WHERE "uploads"."id" = 2 LIMIT 1
b3f67e355ddb366071ee8e088277194d

As you can see, the upload.update!() outside the transaction is still updating the sha1 column even though it's not part of the method call.

@gschlager gschlager merged commit acc73f2 into master Mar 25, 2021
@gschlager gschlager deleted the fix/upload-sha1 branch March 25, 2021 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants