Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Exempt test namespaces from the dynamic-var ratchet (#83348)

Chris Truterb87e6058b037
diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn
index 479bbc5828e..aec31094099 100644
--- a/.clj-kondo/config.edn
+++ b/.clj-kondo/config.edn
@@ -960,6 +960,10 @@
:private-call {:level :off}
:metabase/defsetting-must-specify-export {:level :off}
:metabase/defsetting-namespace {:level :off}
+ ;; Test fixtures and per-test overrides use `binding`-scoped dynamic vars legitimately; this ratchet
+ ;; isn't aimed at that pattern. Mocking functions that way is the narrower case
+ ;; `:metabase/prefer-with-dynamic-fn-redefs` already covers.
+ :metabase/discourage-dynamic-vars {:level :off}
:metabase/t2-query-namespace {:level :off}
:metabase/test-helpers-use-non-thread-safe-functions {:level :warning} ; more config in `.clj-kondo/config/test-helpers/config.edn`
diff --git a/.clj-kondo/ratchets.edn b/.clj-kondo/ratchets.edn
index a1f7ca90a96..2bf65c710a6 100644
--- a/.clj-kondo/ratchets.edn
+++ b/.clj-kondo/ratchets.edn
@@ -60,6 +60,7 @@
:main-without-gen-class 1
:metabase/defsetting-must-specify-export 1
:metabase/defsetting-namespace 1
+ :metabase/discourage-dynamic-vars 1
:metabase/prefer-with-dynamic-fn-redefs 4
:metabase/t2-query-namespace 2
:metabase/table-or-field-query 1
diff --git a/modules/drivers/athena/test/metabase/test/data/athena.clj b/modules/drivers/athena/test/metabase/test/data/athena.clj
index 3bbd72de319..261b3cbc871 100644
--- a/modules/drivers/athena/test/metabase/test/data/athena.clj
+++ b/modules/drivers/athena/test/metabase/test/data/athena.clj
@@ -234,7 +234,6 @@
(u/prog1 (existing-databases*)
(reset! cached-existing-databases <>))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *allow-database-creation*
"Whether to allow database creation. This is normally disabled to prevent people from accidentally loading duplicate
data into Athena or somehow stomping over existing databases and breaking CI. If you want to create a new dataset,
diff --git a/modules/drivers/databricks/test/metabase/test/data/databricks.clj b/modules/drivers/databricks/test/metabase/test/data/databricks.clj
index e1174f4bc44..ea9b8da3be0 100644
--- a/modules/drivers/databricks/test/metabase/test/data/databricks.clj
+++ b/modules/drivers/databricks/test/metabase/test/data/databricks.clj
@@ -99,7 +99,6 @@
;; Dataset can be destroyed using `tx/destroy-db` to remove the data from Databricks instance.
;; [[*allow-database-deletion*]] must be bound to true. Then `t2/delete!` can be used to remove the reference from
;; application database.
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *allow-database-creation*
"Same approach is used in Databricks driver as in Athena. Dataset creation is disabled by default. Datasets are
preloaded in Databricks instance that tests run against. If you need to create new database on the instance,
@@ -123,7 +122,6 @@
(log/infof "Creating Databricks database %s" (pr-str schema))
(apply (get-method tx/create-db! :sql-jdbc/test-extensions) driver dbdef options)))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *allow-database-deletion*
"This is used to control `tx/destroy-db!`. Disabling database deletion is useful in CI. Specifically, if initial sync
of some test dataset our test code destroys the database. In Databricks we want to avoid this, because datasets are
diff --git a/modules/drivers/mongo/test/metabase/test/data/mongo.clj b/modules/drivers/mongo/test/metabase/test/data/mongo.clj
index e728054057d..87f72a87c33 100644
--- a/modules/drivers/mongo/test/metabase/test/data/mongo.clj
+++ b/modules/drivers/mongo/test/metabase/test/data/mongo.clj
@@ -59,7 +59,6 @@
(mongo.connection/with-mongo-database [^MongoDatabase db (tx/dbdef->connection-details driver :server dbdef)]
(.drop db)))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *remove-nil?*
"When creating a dataset, omit any nil-valued fields from the documents."
false)
diff --git a/modules/drivers/oracle/test/metabase/test/data/oracle.clj b/modules/drivers/oracle/test/metabase/test/data/oracle.clj
index 0387b233f9c..41bf0b5bcbe 100644
--- a/modules/drivers/oracle/test/metabase/test/data/oracle.clj
+++ b/modules/drivers/oracle/test/metabase/test/data/oracle.clj
@@ -301,7 +301,6 @@
;; if the ResultSet returns anything we know the table is already loaded.
(.next rset))))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *override-describe-database-to-filter-by-db-name?*
"Whether to override the production implementation for `describe-database` with a special one that only syncs
the tables qualified by the database name. This is `true` by default during tests to fake database isolation.
diff --git a/modules/drivers/redshift/test/metabase/test/data/redshift.clj b/modules/drivers/redshift/test/metabase/test/data/redshift.clj
index 2c43383e0b7..61bbad874af 100644
--- a/modules/drivers/redshift/test/metabase/test/data/redshift.clj
+++ b/modules/drivers/redshift/test/metabase/test/data/redshift.clj
@@ -389,7 +389,6 @@
{:write? true}
delete-session-schema!))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *override-describe-database-to-filter-by-db-name?*
"Whether to override the production implementation for `describe-database` with a special one that only syncs
the tables qualified by the database name. This is `true` by default during tests to fake database isolation.
diff --git a/modules/drivers/vertica/test/metabase/test/data/vertica.clj b/modules/drivers/vertica/test/metabase/test/data/vertica.clj
index 3b4dea50e0e..f6d33f3563d 100644
--- a/modules/drivers/vertica/test/metabase/test/data/vertica.clj
+++ b/modules/drivers/vertica/test/metabase/test/data/vertica.clj
@@ -284,7 +284,6 @@
;; if the ResultSet returns anything we know the table is already loaded.
(.next rset))))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *override-describe-database-to-filter-by-db-name?*
"Whether to override the production implementation for `describe-database` with a special one that only syncs
the tables qualified by the database name. This is `true` by default during tests to fake database isolation.
diff --git a/test/metabase/app_db/custom_migrations/metrics_v2_batch_test.clj b/test/metabase/app_db/custom_migrations/metrics_v2_batch_test.clj
index 66ed429ce7c..15cd0f14089 100644
--- a/test/metabase/app_db/custom_migrations/metrics_v2_batch_test.clj
+++ b/test/metabase/app_db/custom_migrations/metrics_v2_batch_test.clj
@@ -20,7 +20,6 @@
(def ^:private data-file
"metric-v2-test-data.zip")
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic ^FileSystem *data-fs* nil)
(defn- metric-paths
diff --git a/test/metabase/lib/drill_thru/test_util.cljc b/test/metabase/lib/drill_thru/test_util.cljc
index e60418893a3..c53a65437ae 100644
--- a/test/metabase/lib/drill_thru/test_util.cljc
+++ b/test/metabase/lib/drill_thru/test_util.cljc
@@ -116,7 +116,6 @@
(def ^:private TestCase
(test-case-schema))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *native-card-id* nil)
(defonce ^:private last-native-card-id (atom 12))
diff --git a/test/metabase/lib/test_util/generators.cljc b/test/metabase/lib/test_util/generators.cljc
index 65b618cac40..d3c169d3602 100644
--- a/test/metabase/lib/test_util/generators.cljc
+++ b/test/metabase/lib/test_util/generators.cljc
@@ -104,7 +104,6 @@
-1
(tu.rng/rand-int (count (:stages query)))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *safe-for-old-refs*
"Controls whether the generators will construct queries with things like multiple joins to the same table, which
create ambiguous refs in classic MBQL 5.
@@ -332,7 +331,6 @@
(add-step {:kind :join
:weight 30})
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *available-cards*
"To be bound to cards available for use by generator in joins.
@@ -489,7 +487,6 @@
```"
(mk-step-control 0.04 0.16))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *step-control* step-control:default)
(defn- choose-step [kinds]
diff --git a/test/metabase/lib/test_util/generators/filters.cljc b/test/metabase/lib/test_util/generators/filters.cljc
index b2c11f2e07e..83338faaf45 100644
--- a/test/metabase/lib/test_util/generators/filters.cljc
+++ b/test/metabase/lib/test_util/generators/filters.cljc
@@ -87,7 +87,6 @@
:column column}))))
;; Filter clauses ================================================================================
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *filterable-columns* nil)
(defmulti ^:private gen-filter-clause
diff --git a/test/metabase/metabot/test_util.clj b/test/metabase/metabot/test_util.clj
index e61c7006bbb..54e31d590a3 100644
--- a/test/metabase/metabot/test_util.clj
+++ b/test/metabase/metabot/test_util.clj
@@ -15,7 +15,6 @@
(def ^:private fixture-dir "test_resources/llm")
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *live*
"When true, `raw-fixture` makes real API calls even if a cached file exists.
Bind to `true` in the REPL to re-capture all fixtures:
diff --git a/test/metabase/search/test_util.clj b/test/metabase/search/test_util.clj
index b66a87e0f9e..463596f94c9 100644
--- a/test/metabase/search/test_util.clj
+++ b/test/metabase/search/test_util.clj
@@ -11,7 +11,6 @@
[metabase.test :as mt]
[toucan2.core :as t2]))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *user-ctx* nil)
(defmacro with-sync-search-indexing
diff --git a/test/metabase/server/streaming_response_test.clj b/test/metabase/server/streaming_response_test.clj
index 19c46430b46..6b3d8782a96 100644
--- a/test/metabase/server/streaming_response_test.clj
+++ b/test/metabase/server/streaming_response_test.clj
@@ -235,7 +235,6 @@
(finally
(.stop server))))))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *number-of-cans* nil)
(deftest ^:parallel preserve-bindings-test
diff --git a/test/metabase/settings/models/setting/multi_setting_test.clj b/test/metabase/settings/models/setting/multi_setting_test.clj
index b44cd1ac096..f5e1ff8a603 100644
--- a/test/metabase/settings/models/setting/multi_setting_test.clj
+++ b/test/metabase/settings/models/setting/multi_setting_test.clj
@@ -10,7 +10,6 @@
(use-fixtures :once (fixtures/initialize :db))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic ^:private *parakeet* :green-friend)
(multi-setting/define-multi-setting ^:private multi-setting-test-bird-name
diff --git a/test/metabase/settings/models/setting_test.clj b/test/metabase/settings/models/setting_test.clj
index daee5081935..4653754c0ad 100644
--- a/test/metabase/settings/models/setting_test.clj
+++ b/test/metabase/settings/models/setting_test.clj
@@ -99,7 +99,6 @@
:init (comp str random-uuid)
:encryption :when-encryption-key-set)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *enabled?* false)
(defsetting test-enabled-setting-no-default
diff --git a/test/metabase/sso/ldap_test_util.clj b/test/metabase/sso/ldap_test_util.clj
index 8df965e5ecb..2a28cb3f784 100644
--- a/test/metabase/sso/ldap_test_util.clj
+++ b/test/metabase/sso/ldap_test_util.clj
@@ -11,7 +11,6 @@
(set! *warn-on-reflection* true)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic ^InMemoryDirectoryServer *ldap-server*
"An in-memory LDAP testing server."
nil)
diff --git a/test/metabase/test/data/env.clj b/test/metabase/test/data/env.clj
index 081217da266..8e4c3a00e41 100644
--- a/test/metabase/test/data/env.clj
+++ b/test/metabase/test/data/env.clj
@@ -35,7 +35,6 @@
{:pre [((some-fn sequential? set?) drivers)]}
(reset! default-test-drivers (set drivers)))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(defn- ^:dynamic *test-drivers*
[]
(or @default-test-drivers
diff --git a/test/metabase/test/data/mbql_query_impl.cljc b/test/metabase/test/data/mbql_query_impl.cljc
index 967e47a42e6..e61cd7c7bc8 100644
--- a/test/metabase/test/data/mbql_query_impl.cljc
+++ b/test/metabase/test/data/mbql_query_impl.cljc
@@ -22,13 +22,9 @@
(apply (requiring-resolve 'metabase.test.data/id) args))))
;; TODO: druid-id-fn is just temporary until I figure out proper solution for rebinding that symb.
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *id-fn-symb* `druid-id-fn #_'metabase.test.data/id)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *field-name-fn-symb* `field-name)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *field-base-type-fn-symb* `field-base-type)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic ^Long *mbql-version* 4)
(defn- token->sigil [token]
diff --git a/test/metabase/test/data/sql_jdbc/load_data.clj b/test/metabase/test/data/sql_jdbc/load_data.clj
index 67c70dc2f7c..e0f0f89fec2 100644
--- a/test/metabase/test/data/sql_jdbc/load_data.clj
+++ b/test/metabase/test/data/sql_jdbc/load_data.clj
@@ -24,7 +24,6 @@
(set! *warn-on-reflection* true)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *disable-fk-checks*
"When bound to `true`, drivers that support it (e.g., MySQL) will disable foreign key checks during data insertion.
This is useful for tests that need to insert self-referencing data in a single batch."
diff --git a/test/metabase/test/http_client.clj b/test/metabase/test/http_client.clj
index 5231057787f..b225282270d 100644
--- a/test/metabase/test/http_client.clj
+++ b/test/metabase/test/http_client.clj
@@ -41,7 +41,6 @@
;;; build-url
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *url-prefix*
"Prefix to automatically prepend to the URL of calls made with `client`."
"/api")
diff --git a/test/metabase/test/initialize.clj b/test/metabase/test/initialize.clj
index aa42a30a553..7f5d6323e2c 100644
--- a/test/metabase/test/initialize.clj
+++ b/test/metabase/test/initialize.clj
@@ -25,7 +25,6 @@
(def ^:private init-timeout-ms (u/seconds->ms 120))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *initializing*
"Collection of components that are being currently initialized by the current thread."
[])
diff --git a/test/metabase/test/util/dynamic_redefs.clj b/test/metabase/test/util/dynamic_redefs.clj
index 368ec10cee7..88126b1087d 100644
--- a/test/metabase/test/util/dynamic_redefs.clj
+++ b/test/metabase/test/util/dynamic_redefs.clj
@@ -4,12 +4,10 @@
(set! *warn-on-reflection* true)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *local-redefs*
"A thread-local mapping from vars to their most recently bound definition."
{})
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:private ^:dynamic *proxy-depths*
"Thread-local map from redefined var to current recursion depth through its proxy.
Used to detect capture bugs that would otherwise manifest as StackOverflowError."
diff --git a/test/metabase/test/util/random.clj b/test/metabase/test/util/random.clj
index 997fcc25c6c..cbdb0e45d5a 100644
--- a/test/metabase/test/util/random.clj
+++ b/test/metabase/test/util/random.clj
@@ -5,7 +5,6 @@
(set! *warn-on-reflection* true)
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(defonce
^{:dynamic true
:doc "Generator that could be rebound. Bind when you need to control the seed for exmaple."}
diff --git a/test/metabase/test/util/thread_local.clj b/test/metabase/test/util/thread_local.clj
index ba94f73e84e..2023de6707b 100644
--- a/test/metabase/test/util/thread_local.clj
+++ b/test/metabase/test/util/thread_local.clj
@@ -4,7 +4,6 @@
[mb.hawk.parallel]
[metabase.util :as u]))
-#_{:clj-kondo/ignore [:metabase/discourage-dynamic-vars]}
(def ^:dynamic *thread-local*
"Whether test helpers should set thread-local values for things, as opposed to setting global values."
true)