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: remove uploaded files if transaction is rolled back #2546

Merged
merged 3 commits into from May 28, 2021

Conversation

fsateler
Copy link
Contributor

This prevents accumulating stale files when transaction is aborted.

Depends on #2545 , restores functionality added by #2209

@mshibuya
Copy link
Member

These tests need to be added back to ensure that this change has the effect intended in #2209.
88e3717#diff-48bc92466ff9653e1ae5c5b60134a0c7c631b0d414f0d9b0b4642e84097a650bL790-L828

In addition to that, you need to add tests for the functionality stated in #2544.

@fsateler
Copy link
Contributor Author

These tests need to be added back to ensure that this change has the effect intended in #2209.
88e3717#diff-48bc92466ff9653e1ae5c5b60134a0c7c631b0d414f0d9b0b4642e84097a650bL790-L828

The tests are there. They are reverted in the first commit but re-added in the second.

In addition to that, you need to add tests for the functionality stated in #2544.

The tests are already there. By reading public_path instead of file_path, the tests were reading temporary files instead of the definitive one (ie, they were reading the bogus urls).

Do you have a specific test in mind?

@mshibuya
Copy link
Member

These tests need to be added back...

The tests are there.

Sorry I overlooked, please ignore this.

Do you have a specific test in mind?

These points are stated in #2544, so we should have corresponding test cases to ensure they are resolved by this change.

For example, reading my_object.file_url.url will return a bogus url if I read before commit.
For example, if there is a network failure. This causes the transaction to not be rolled back and invalid records being recorded.

@fsateler
Copy link
Contributor Author

These points are stated in #2544, so we should have corresponding test cases to ensure they are resolved by this change.

For example, reading my_object.file_url.url will return a bogus url if I read before commit.
For example, if there is a network failure. This causes the transaction to not be rolled back and invalid records being recorded.

Done.

@tomprats
Copy link
Contributor

tomprats commented Apr 6, 2021

Would just like to echo that moving this back to a before_save is very helpful. I've been getting a mysterious: OpenURI::HTTPError: 403 Forbidden in a background job triggered in an after_commit ever since I upgraded to 2. What confused me even more was that it always succeeds when retried.

Appreciate the work on this!

@mshibuya mshibuya added this to the Release v3.0.0 milestone May 7, 2021
This commit attempts to fix leftover files in failed transactions, but
in the process introduces three problems:

- Uploader state is inconsistent between `save` and `commit`. For example, reading `my_object.file_url.url` will return a bogus url if I read before commit.
- A file might not be uploaded after a successful commit. For example, if there is a network failure. This causes the transaction to not be rolled back and invalid records being recorded.
- Even if the upload eventually completes, it can take an arbitrary amount of time, during which the record is invalid.

This reverts commit 665f225.

Fixes: carrierwaveuploader#2544
This prevents accumulating stale files when transaction is aborted.
@mshibuya mshibuya merged commit 6c1140b into carrierwaveuploader:master May 28, 2021
@mshibuya
Copy link
Member

Thank you for your work 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants