From c1d6bc945e6be2751a8a88934df354fefa441f27 Mon Sep 17 00:00:00 2001 From: lbrdnk <lbrdnk@users.noreply.github.com> Date: Sat, 21 Sep 2024 23:10:51 +0300 Subject: [PATCH] Revert "Tweak some sheet around CSV uploads (#48000)" This reverts commit 48aad35c79495ae779d7237eb99098a25119e210. --- .../serialization/api_test.clj | 14 ++++++++------ src/metabase/api/card.clj | 5 ++--- src/metabase/search/postgres/core.clj | 16 ++-------------- src/metabase/upload.clj | 2 +- src/metabase/upload/parsing.clj | 1 - test/metabase/search/postgres/core_test.clj | 7 +++++-- 6 files changed, 18 insertions(+), 27 deletions(-) diff --git a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj index e685a2f64de..9dd0e97ccdb 100644 --- a/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj +++ b/enterprise/backend/test/metabase_enterprise/serialization/api_test.clj @@ -181,7 +181,7 @@ "secrets" false "success" true "error_message" nil} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))) (testing "POST /api/ee/serialization/import" (t2/update! :model/Card {:id (:id card)} {:name (str "qwe_" (:name card))}) @@ -205,7 +205,7 @@ "error_count" 0 "success" true "error_message" nil} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))))) (mt/with-dynamic-redefs [v2.load/load-one! (let [load-one! (mt/dynamic-value #'v2.load/load-one!)] (fn [ctx path & [modfn]] @@ -222,6 +222,8 @@ {:file ba})) log (slurp (io/input-stream res))] (testing "3 header lines, then cards+database+collection, then the error" + (is (= #{"Card" "Database" "Collection"} + (log-types (str/split-lines log)))) (is (re-find #"Failed to read file for Collection DoesNotExist" log)) (is (re-find #"Cannot find file entry" log)) ;; underlying error (is (= {:deps-chain #{[{:id "**ID**", :model "Card"}]}, @@ -239,7 +241,7 @@ "count" 0 "error_count" 0 "error_message" #"(?s)Failed to read file for Collection DoesNotExist.*"} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))))) (testing "Skipping errors /api/ee/serialization/import" (let [res (mt/user-http-request :crowberto :post 200 "ee/serialization/import" @@ -260,7 +262,7 @@ "count" 2 "error_count" 1 "models" "Collection,Dashboard"} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))))))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))))))) (mt/with-dynamic-redefs [serdes/extract-one (extract-one-error (:entity_id card) (mt/dynamic-value serdes/extract-one))] @@ -290,7 +292,7 @@ "secrets" false "success" false "error_message" #"(?s)Exception extracting Card \d+ .*"} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))) (testing "Full stacktrace" (binding [api.serialization/*additive-logging* false] @@ -331,7 +333,7 @@ "secrets" false "success" true "error_message" nil} - (-> (snowplow-test/pop-event-data-and-user-id!) last :data)))))) + (-> (snowplow-test/pop-event-data-and-user-id!) first :data)))))) (testing "Only admins can export/import" (is (= "You don't have permissions to do that." diff --git a/src/metabase/api/card.clj b/src/metabase/api/card.clj index b5cbb6cde20..68ff3251eb5 100644 --- a/src/metabase/api/card.clj +++ b/src/metabase/api/card.clj @@ -888,9 +888,8 @@ :db-id (or (:db_id uploads-db-settings) (throw (ex-info (tru "The uploads database is not configured.") {:status-code 422})))})] - {:status 200 - :body (:id model) - :headers {"metabase-table-id" (str (:table-id model))}}) + {:status 200 + :body (:id model)}) (catch Throwable e {:status (or (-> e ex-data :status-code) 500) diff --git a/src/metabase/search/postgres/core.clj b/src/metabase/search/postgres/core.clj index 26c80f12452..2ab4c0962e6 100644 --- a/src/metabase/search/postgres/core.clj +++ b/src/metabase/search/postgres/core.clj @@ -8,11 +8,7 @@ [metabase.search.impl :as search.impl] [metabase.search.postgres.index :as search.index] [metabase.search.postgres.ingestion :as search.ingestion] - [toucan2.core :as t2]) - (:import - (java.time OffsetDateTime))) - -(set! *warn-on-reflection* true) + [toucan2.core :as t2])) (defn- user-params [search-ctx] (cond @@ -83,10 +79,6 @@ (t2/query <>) (filter (comp (set ids) :id) <>))))))) -(defn- parse-datetime [s] - (when s - (OffsetDateTime/parse s))) - (defn- minimal [search-term & {:as _search-ctx}] (when-not @#'search.index/initialized? (throw (ex-info "Search index is not initialized. Use [[init!]] to ensure it exists." @@ -94,11 +86,7 @@ (->> (assoc (search.index/search-query search-term) :select [:legacy_input]) (t2/query) (map :legacy_input) - (map #(json/parse-string % keyword)) - (map #(-> % - (update :created_at parse-datetime) - (update :updated_at parse-datetime) - (update :last_edited_at parse-datetime))))) + (map #(json/parse-string % keyword)))) (def ^:private default-engine hybrid-multi) diff --git a/src/metabase/upload.clj b/src/metabase/upload.clj index 163a4897ade..2dfddb79925 100644 --- a/src/metabase/upload.clj +++ b/src/metabase/upload.clj @@ -633,7 +633,7 @@ (assoc stats :event :csv-upload-successful :model-id (:id card))) - (assoc card :table-id (:id table))) + card) (catch Throwable e (snowplow/track-event! ::snowplow/csvupload (assoc (fail-stats filename file) :event :csv-upload-failed)) diff --git a/src/metabase/upload/parsing.clj b/src/metabase/upload/parsing.clj index 5fb27c0a0cc..fae6a62ab2a 100644 --- a/src/metabase/upload/parsing.clj +++ b/src/metabase/upload/parsing.clj @@ -47,7 +47,6 @@ "d MMMM, uuuu" ; 30 January, 2000 "EEEE, MMMM d uuuu" ; Sunday, January 30 2000 "EEEE, MMMM d, uuuu" ; Sunday, January 30, 2000 - "EEE MMM dd uuuu HH:mm:ss 'GMT'Z (zzzz)" ; The format produced by exporting Google Sheets ]) (def local-date-formatter diff --git a/test/metabase/search/postgres/core_test.clj b/test/metabase/search/postgres/core_test.clj index 906da1d7c1b..f296eefd240 100644 --- a/test/metabase/search/postgres/core_test.clj +++ b/test/metabase/search/postgres/core_test.clj @@ -58,11 +58,14 @@ (is (= (hybrid term) (hybrid-multi term)))))))) +(defn- remove-time [m] + (dissoc m :created_at :updated_at :last_edited_at)) + (deftest minimal-test (with-setup (testing "consistent results between both hybrid implementations\n" (doseq [term example-terms] (testing term ;; Timestamps are not strings after round trip, but this doesn't matter - (is (= (hybrid term) - (minimal term)))))))) + (is (= (map remove-time (hybrid term)) + (map remove-time (minimal term))))))))) -- GitLab