18122: Fix "get collection by pdh" when manifest_text is unselected.
[arvados.git] / services / api / app / controllers / arvados / v1 / collections_controller.rb
index 1b0850a5802eab5e7b451cf40ac1beecf392a61b..c9b36e19ed95dedca95d9fd473af748088641d33 100644 (file)
@@ -80,18 +80,22 @@ class Arvados::V1::CollectionsController < ApplicationController
       # it will select the Collection object with the longest
       # available lifetime.
 
+      select_attrs = (@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]
       if c = Collection.
                readable_by(*@read_users, opts).
                where({ portable_data_hash: loc.to_s }).
                order("trash_at desc").
-               select(((@select || ["manifest_text"]) | ["portable_data_hash", "trash_at"]).join(", ")).
+               select(select_attrs.join(", ")).
                limit(1).
                first
         @object = {
           uuid: c.portable_data_hash,
           portable_data_hash: c.portable_data_hash,
-          manifest_text: c.manifest_text,
+          trash_at: c.trash_at,
         }
+        if select_attrs.index("manifest_text")
+          @object[:manifest_text] = c.manifest_text
+        end
       end
     else
       super