FIX: `fix_missing_s3` task fails on failed upload (take 2) (#13660)

FIX: fix_missing_s3 task fails on failed upload (take 2) (#13660)

ref: https://github.com/discourse/discourse/commit/935aadbfddc6ece3742163e9d878a75617292e64

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 4ae945c..a481b23 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -1037,10 +1037,17 @@ def fix_missing_s3
       else
         # we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
         # we may end up breaking posts
-        upload.assign_attributes(etag: fixed_upload.etag, url: fixed_upload.url, verification_status: Upload.verification_statuses[:unchecked])
-        saved = upload.save(validate: false)
+        save_error = nil
+        begin
+          upload.assign_attributes(etag: fixed_upload.etag, url: fixed_upload.url, verification_status: Upload.verification_statuses[:unchecked])
+          upload.save!(validate: false)
+        rescue => save_error
+          # url might be null
+        end
 
-        if saved
+        if save_error
+          puts "Failed to save upload #{saved.errors.full_messages}"
+        else
           OptimizedImage.where(upload_id: upload.id).destroy_all
           rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id)
 
@@ -1050,8 +1057,6 @@ def fix_missing_s3
               post.rebake!
             end
           end
-        else
-          puts "Failed to save upload #{saved.errors.full_messages}"
         end
       end
     end

GitHub sha: 236d6d91b2d73590def3a4967eaae4dc6d7c1804

This commit appears in #13660 which was approved by CvX. It was merged by techAPJ.