FIX: skip uploads without etag in s3 inventory check.

FIX: skip uploads without etag in s3 inventory check.

diff --git a/Gemfile.lock b/Gemfile.lock
index b625d8d..fbc5593 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -533,4 +533,4 @@ DEPENDENCIES
   webpush
 
 BUNDLED WITH
-   1.17.3
+   2.0.1
diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index 2fa3676..77c61ca 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -55,7 +55,9 @@ class S3Inventory
           list_missing_post_uploads if type == "original"
 
           uploads = (model == Upload) ? model.by_users.where("created_at < ?", inventory_date) : model
-          missing_uploads = uploads.joins("LEFT JOIN #{table_name} ON #{table_name}.etag = #{model.table_name}.etag").where("#{table_name}.etag is NULL")
+          missing_uploads = uploads
+            .joins("LEFT JOIN #{table_name} ON #{table_name}.etag = #{model.table_name}.etag")
+            .where("#{table_name}.etag IS NULL AND #{model.table_name}.etag IS NOT NULL")
 
           if (missing_count = missing_uploads.count) > 0
             missing_uploads.select(:id, :url).find_each do |upload|
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index 6c26dcd..44ae55c 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -65,6 +65,7 @@ describe "S3Inventory" do
 
     upload = Fabricate(:upload, etag: "ETag", created_at: 1.days.ago)
     Fabricate(:upload, etag: "ETag2", created_at: Time.now)
+    Fabricate(:upload, created_at: 2.days.ago)
 
     inventory.expects(:download_inventory_files_to_tmp_directory)
     inventory.expects(:decompress_inventory_files)
@@ -75,7 +76,7 @@ describe "S3Inventory" do
       inventory.backfill_etags_and_list_missing
     end
 
-    expect(output).to eq("Listing missing post uploads...\n0 post uploads are missing.\n#{upload.url}\n1 of 4 uploads are missing\n")
+    expect(output).to eq("Listing missing post uploads...\n0 post uploads are missing.\n#{upload.url}\n1 of 5 uploads are missing\n")
     expect(Discourse.stats.get("missing_s3_uploads")).to eq(1)
   end

GitHub sha: 2a7065c5

1 Like

I am reverting this… I assume this was by mistake.

DEV: revert bundler to 1.7.3