diff --git a/src/metabase/models/card.clj b/src/metabase/models/card.clj index 57d28e5c862b1d4c1ac3db955f25381725e06e66..2a204c767a2ebee1cc6851b20f37b344c81e727a 100644 --- a/src/metabase/models/card.clj +++ b/src/metabase/models/card.clj @@ -595,8 +595,7 @@ card.metadata/populate-result-metadata) pre-update populate-query-fields - maybe-populate-initially-published-at - (dissoc :id))) + maybe-populate-initially-published-at)) ;; Cards don't normally get deleted (they get archived instead) so this mostly affects tests (t2/define-before-delete :model/Card diff --git a/test/metabase/models/card_test.clj b/test/metabase/models/card_test.clj index eee2dc0903cc050907e5ffceaeb0b337ab7375e4..44c2ef1b54a5ac74026344bc4ecd1e82ea24a7e7 100644 --- a/test/metabase/models/card_test.clj +++ b/test/metabase/models/card_test.clj @@ -1089,3 +1089,17 @@ [[1 {:parameter_mappings [{:target [:dimension [:field 10 {:temporal-unit :month}]]} {:target [:dimension [:field 33 {:temporal-unit :month}]]} {:target [:dimension [:field 10 {:temporal-unit :month}]]}]}]])) + +(deftest update-does-not-break + ;; There's currently a footgun in Toucan2 - if 1) the result of `before-update` doesn't have an ID, 2) part of your + ;; `update` would change a subset of selected rows, and 3) part of your `update` would change *every* selected row + ;; (in this case, that's the `updated_at` we automatically set), then it emits an update without a `WHERE` clause. + ;; + ;;This can be removed after https://github.com/camsaul/toucan2/pull/196 is merged. + (mt/with-temp [:model/Card {card-1-id :id} {:name "Flippy"} + :model/Card {card-2-id :id} {:name "Dog Man"} + :model/Card {card-3-id :id} {:name "Petey"}] + (testing "only the two cards specified get updated" + (t2/update! :model/Card :id [:in [card-1-id card-2-id]] + {:name "Flippy"}) + (is (= "Petey" (t2/select-one-fn :name :model/Card :id card-3-id))))))