Skip to content

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

[Transform python] python lib apis and settings (#63568)

Ngoc Khuat98e29f6c39c5
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 0f8699e13ac..1b956112090 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -1721,7 +1721,6 @@
settings
util}}
-
enterprise/embedding-hub
{:team "Embedding"
:api #{metabase-enterprise.embedding-hub.api}
@@ -1969,8 +1968,10 @@
{:team "Querying"
:api #{metabase-enterprise.transforms.api
metabase-enterprise.transforms.core
- metabase-enterprise.transforms.init}
- :uses #{api
+ metabase-enterprise.transforms.init
+ metabase-enterprise.transforms.util}
+ :uses #{analytics
+ api
app-db
config
driver
@@ -1986,7 +1987,24 @@
sync
task
task-history
- util}}
+ upload
+ util
+ enterprise/transforms-python}}
+
+ enterprise/transforms-python
+ {:team "Querying"
+ :api #{metabase-enterprise.transforms-python.api
+ metabase-enterprise.transforms-python.init
+ metabase-enterprise.transforms-python.settings}
+ :uses #{api
+ app-db
+ config
+ driver
+ models
+ query-processor
+ settings
+ util
+ enterprise/transforms}}
enterprise/upload-management
{:team "UX West"
diff --git a/enterprise/backend/src/metabase_enterprise/api/routes.clj b/enterprise/backend/src/metabase_enterprise/api/routes.clj
index 04984c2b5e7..18a010c7264 100644
--- a/enterprise/backend/src/metabase_enterprise/api/routes.clj
+++ b/enterprise/backend/src/metabase_enterprise/api/routes.clj
@@ -33,6 +33,7 @@
[metabase-enterprise.semantic-search.api]
[metabase-enterprise.serialization.api]
[metabase-enterprise.stale.api]
+ [metabase-enterprise.transforms-python.api]
[metabase-enterprise.transforms.api]
[metabase-enterprise.upload-management.api]
[metabase.api.macros :as api.macros]
@@ -52,6 +53,7 @@
:collection-cleanup (deferred-tru "Collection Cleanup")
:content-translation (deferred-tru "Content translation")
:documents (deferred-tru "Documents")
+ :embedding (deferred-tru "Embedding")
:etl-connections (deferred-tru "ETL Connections")
:etl-connections-pg (deferred-tru "ETL Connections PG replication")
:llm-autodescription (deferred-tru "LLM Auto-description")
@@ -64,7 +66,7 @@
:upload-management (deferred-tru "Upload Management")
:database-routing (deferred-tru "Database Routing")
:cloud-custom-smtp (deferred-tru "Custom SMTP")
- :embedding (deferred-tru "Embedding")})
+ :transforms-python (deferred-tru "Transforms Python")})
(defn- premium-handler [handler required-feature]
(let [handler (cond-> handler
@@ -112,6 +114,7 @@
"/metabot-tools" metabase-enterprise.metabot-v3.tools.api/routes
"/metabot-v3" (premium-handler metabase-enterprise.metabot-v3.api/routes :metabot-v3)
"/permission_debug" (premium-handler metabase-enterprise.permission-debug.api/routes :advanced-permissions)
+ "/transforms-python" (premium-handler metabase-enterprise.transforms-python.api/routes :transforms-python)
"/scim" (premium-handler metabase-enterprise.scim.routes/routes :scim)
"/semantic-search" (premium-handler metabase-enterprise.semantic-search.api/routes :semantic-search)
"/serialization" (premium-handler metabase-enterprise.serialization.api/routes :serialization)
diff --git a/enterprise/backend/src/metabase_enterprise/core/init.clj b/enterprise/backend/src/metabase_enterprise/core/init.clj
index 992c27a7b5d..ac1b618e720 100644
--- a/enterprise/backend/src/metabase_enterprise/core/init.clj
+++ b/enterprise/backend/src/metabase_enterprise/core/init.clj
@@ -20,4 +20,5 @@
[metabase-enterprise.semantic-search.init]
[metabase-enterprise.sso.init]
[metabase-enterprise.stale.init]
+ [metabase-enterprise.transforms-python.init]
[metabase-enterprise.transforms.init]))
diff --git a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
index 0be2d0c7cb0..69e4a02d82b 100644
--- a/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
+++ b/enterprise/backend/src/metabase_enterprise/serialization/v2/models.clj
@@ -79,6 +79,7 @@
"PermissionsGroupMembership"
"PermissionsRevision"
"PersistedInfo"
+ "PythonLibrary"
"Pulse"
"PulseCard"
"PulseChannel"
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj
new file mode 100644
index 00000000000..6954f7addb8
--- /dev/null
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/api.clj
@@ -0,0 +1,30 @@
+(ns metabase-enterprise.transforms-python.api
+ (:require
+ [metabase-enterprise.transforms-python.models.python-library :as python-library]
+ [metabase.api.common :as api]
+ [metabase.api.macros :as api.macros]
+ [metabase.api.routes.common :refer [+auth]]
+ [metabase.api.util.handlers :as handlers]))
+
+(api.macros/defendpoint :get "/library/:path"
+ "Get the Python library for user modules."
+ [{:keys [path]} :- [:map [:path :string]]
+ _query-params]
+ (api/check-superuser)
+ (-> (python-library/get-python-library-by-path path)
+ api/check-404
+ (select-keys [:source :path :created_at :updated_at])))
+
+(api.macros/defendpoint :put "/library/:path"
+ "Update the Python library source code for user modules."
+ [{:keys [path]} :- [:map [:path :string]]
+ _query-params
+ body :- [:map {:closed true}
+ [:source :string]]]
+ (api/check-superuser)
+ (python-library/update-python-library-source! path (:source body)))
+
+(def ^{:arglists '([request respond raise])} routes
+ "`/api/ee/transforms-python` routes."
+ (handlers/routes
+ (api.macros/ns-handler *ns* +auth)))
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/init.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/init.clj
new file mode 100644
index 00000000000..e33b623721d
--- /dev/null
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/init.clj
@@ -0,0 +1,5 @@
+(ns metabase-enterprise.transforms-python.init
+ (:require
+ [metabase-enterprise.transforms-python.settings]))
+
+(comment metabase-enterprise.transforms-python.settings/keepme)
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj
new file mode 100644
index 00000000000..6b3f7c63edb
--- /dev/null
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/models/python_library.clj
@@ -0,0 +1,61 @@
+(ns metabase-enterprise.transforms-python.models.python-library
+ (:require
+ [metabase.app-db.core :as app-db]
+ [metabase.util.i18n :refer [tru]]
+ [methodical.core :as methodical]
+ [toucan2.core :as t2]))
+
+(set! *warn-on-reflection* true)
+
+(methodical/defmethod t2/table-name :model/PythonLibrary [_model] :python_library)
+
+(defn- normalize-path
+ "Ensure the path ends with .py extension."
+ [path]
+ (if (.endsWith ^String path ".py")
+ path
+ (str path ".py")))
+
+(t2/define-before-insert :model/PythonLibrary
+ [library]
+ (update library :path normalize-path))
+
+(t2/define-before-update :model/PythonLibrary
+ [library]
+ (if (:path library)
+ (update library :path normalize-path)
+ library))
+
+(doseq [trait [:metabase/model :hook/timestamped?]]
+ (derive :model/PythonLibrary trait))
+
+(def ^:private allowed-paths
+ "Set of allowed library paths. Currently only 'common' is supported."
+ #{"common.py"})
+
+(defn- validate-path!
+ "Validates that the given path is allowed. Throws an exception if not."
+ [path]
+ (let [normalized-path (normalize-path path)]
+ (when-not (contains? allowed-paths normalized-path)
+ (throw (ex-info (tru "Invalid library path. Only ''common'' is currently supported.")
+ {:status-code 400
+ :path normalized-path
+ :allowed-paths allowed-paths})))))
+
+(defn get-python-library-by-path
+ "Get the Python library by path."
+ [path]
+ (let [normalized-path (normalize-path path)]
+ (validate-path! normalized-path)
+ (t2/select-one :model/PythonLibrary :path normalized-path)))
+
+(defn update-python-library-source!
+ "Update the Python library source code. Creates a new record if none exists. Returns the updated library."
+ [path source]
+ (let [normalized-path (normalize-path path)]
+ (validate-path! normalized-path)
+ (let [id (app-db/update-or-insert! :model/PythonLibrary
+ {:path normalized-path}
+ (constantly {:path normalized-path :source source}))]
+ (t2/select-one :model/PythonLibrary id))))
diff --git a/enterprise/backend/src/metabase_enterprise/transforms_python/settings.clj b/enterprise/backend/src/metabase_enterprise/transforms_python/settings.clj
new file mode 100644
index 00000000000..2ae3fa46444
--- /dev/null
+++ b/enterprise/backend/src/metabase_enterprise/transforms_python/settings.clj
@@ -0,0 +1,115 @@
+(ns metabase-enterprise.transforms-python.settings
+ (:require
+ [metabase.config.core :as config]
+ [metabase.settings.core :as setting]
+ [metabase.util.i18n :refer [deferred-tru]]))
+
+(setting/defsetting python-runner-url
+ (deferred-tru "URL for the Python execution server that runs transform functions.")
+ :type :string
+ :visibility :admin
+ :default (when (not config/is-prod?) "http://localhost:5001")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-runner-api-token
+ (deferred-tru "API token for authorizing with the python-runner service.")
+ :type :string
+ :visibility :internal
+ :default (when (not config/is-prod?) "dev-token-12345")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :when-encryption-key-set
+ :audit :never)
+
+(setting/defsetting python-storage-s-3-endpoint
+ (deferred-tru "S3 endpoint URL for storing Python execution artifacts.")
+ :type :string
+ :visibility :admin
+ :default (when (not config/is-prod?) "http://localhost:4566")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-region
+ (deferred-tru "AWS region for S3 storage.")
+ :type :string
+ :visibility :admin
+ :default (when (not config/is-prod?) "us-east-1")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-bucket
+ (deferred-tru "S3 bucket name for storing Python execution artifacts.")
+ :type :string
+ :visibility :admin
+ :default (if (not config/is-prod?) "metabase-python-runner" "metabase-cloud-python-runner-staging")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-prefix
+ (deferred-tru "Prefix to use for S3 objects. Necessary in prod where we only have access to a particular prefix.")
+ :type :string
+ :visibility :admin
+ :feature :transforms-python
+ :default (if (not config/is-prod?) "test-prefix" "hosting-4b9351bb22b84791")
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-access-key
+ (deferred-tru "AWS access key ID for S3 authentication.")
+ :type :string
+ :visibility :admin
+ :feature :transforms-python
+ :default (when (not config/is-prod?) "test")
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-secret-key
+ (deferred-tru "AWS secret access key for S3 authentication.")
+ :type :string
+ :visibility :admin
+ :feature :transforms-python
+ :default (when (not config/is-prod?) "test")
+ :doc false
+ :export? false
+ :encryption :when-encryption-key-set
+ :audit :never)
+
+(setting/defsetting python-storage-s-3-container-endpoint
+ (deferred-tru "Alternative S3 endpoint accessible from containers. Leave empty if same as main endpoint.")
+ :type :string
+ :visibility :admin
+ :default (when (not config/is-prod?) "http://localstack:4566")
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
+
+(setting/defsetting python-storage-s-3-path-style-access
+ (deferred-tru "Use path-style access for S3 requests (required for LocalStack and some S3-compatible services).")
+ :type :boolean
+ :visibility :admin
+ :default (when (not config/is-prod?) true)
+ :feature :transforms-python
+ :doc false
+ :export? false
+ :encryption :no
+ :audit :getter)
diff --git a/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj b/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj
index c616b349a3a..10cc6f10d9f 100644
--- a/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/models/entity_id_test.clj
@@ -91,6 +91,7 @@
:model/TransformJobTransformTag
:model/TransformTag
:model/TransformTransformTag
+ :model/PythonLibrary
:model/Undo
:model/User
:model/UserParameterValue
diff --git a/enterprise/backend/test/metabase_enterprise/transforms/execute_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/execute_test.clj
index f1f052516c4..c0908fc6403 100644
--- a/enterprise/backend/test/metabase_enterprise/transforms/execute_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/transforms/execute_test.clj
@@ -30,7 +30,13 @@
:filter-fn constraint-fn
:filter-values constraint-params})))
+(defn- table-name->qp-table
+ [mp table-name]
+ (->> table-name mt/id (lib.metadata/table mp)))
+
(defn- wait-for-table
+ "Wait for a table to appear in metadata, with timeout.
+ Copied from execute_test.clj - will consolidate later."
[table-name timeout-ms]
(let [mp (mt/metadata-provider)
limit (+ (System/currentTimeMillis) timeout-ms)]
@@ -59,15 +65,15 @@
:query t1-query}
:target target1}]
(transforms.execute/run-mbql-transform! t1 {:run-method :manual})
- (let [table1 (wait-for-table table1-name 10000)
- t2-query (make-query table1 "category" lib/= "Gizmo")]
+ (let [table1 (wait-for-table table1-name 10000)
+ t2-query (make-query (->> table1 :name (table-name->qp-table (mt/metadata-provider))) "category" lib/= "Gizmo")]
(mt/with-temp [:model/Transform t2 {:name "transform2"
:source {:type :query
:query t2-query}
:target target2}]
(transforms.execute/run-mbql-transform! t2 {:run-method :cron})
(let [table2 (wait-for-table table2-name 10000)
- check-query (lib/aggregate (make-query table2) (lib/count))
+ check-query (lib/aggregate (make-query (->> table2 :name (table-name->qp-table (mt/metadata-provider)))) (lib/count))
query-result (qp/process-query check-query)]
;; The transforms-test dataset has exactly 4 Gizmo products (IDs 6, 8, 12, 14)
;; First transform filters for categories starting with "G" (Gadget and Gizmo)
@@ -117,7 +123,8 @@
(doseq [transform [transform-no-limit transform-limit]]
(transforms.execute/run-mbql-transform! transform {:run-method :manual})
(let [table-name (-> transform :target :name)
- table-result (wait-for-table table-name 10000)
+ _ (wait-for-table table-name 10000)
+ table-result (lib.metadata/table mp (mt/id (keyword table-name)))
query-result (->> (lib/query mp table-result)
(qp/process-query)
(mt/formatted-rows [str 2.0])
@@ -196,7 +203,8 @@
:query query}
:target target-table}]
(transforms.execute/run-mbql-transform! transform {:run-method :manual})
- (let [table-result (wait-for-table (:name target-table) 10000)
+ (let [_ (wait-for-table (:name target-table) 10000)
+ table-result (lib.metadata/table mp (mt/id (keyword (:name target-table))))
query-result (->> (lib/query mp table-result)
(qp/process-query)
(mt/formatted-rows [int str str 2.0 str])
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/api_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/api_test.clj
new file mode 100644
index 00000000000..9bd003ed532
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/api_test.clj
@@ -0,0 +1,89 @@
+(ns metabase-enterprise.transforms-python.api-test
+ "Tests for /api/ee/transforms-python endpoints."
+ (:require
+ [clojure.test :refer :all]
+ [metabase-enterprise.transforms-python.models.python-library :as python-library]
+ [metabase.test :as mt]
+ [toucan2.core :as t2]))
+
+(set! *warn-on-reflection* true)
+
+(deftest get-library-path-test
+ (testing "GET /api/ee/transforms-python/library/:path"
+ (mt/with-premium-features #{:transforms-python}
+ (testing "requires superuser permissions"
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :get 403 "ee/transforms-python/library/common"))))
+
+ (testing "returns nil when no library exists"
+ (t2/delete! :model/PythonLibrary)
+ (is (= "Not found." (mt/user-http-request :crowberto :get 404 "ee/transforms-python/library/common"))))
+
+ (testing "returns existing library"
+ (t2/delete! :model/PythonLibrary)
+ (python-library/update-python-library-source! "common" "def my_function():\n return 42")
+ (is (=? {:source "def my_function():\n return 42"
+ :path "common.py"
+ :created_at some?
+ :updated_at some?}
+ (mt/user-http-request :crowberto :get 200 "ee/transforms-python/library/common"))))
+
+ (testing "rejects invalid paths"
+ (is (= "Invalid library path. Only 'common' is currently supported."
+ (:message (mt/user-http-request :crowberto :get 400 "ee/transforms-python/library/invalid-path"))))))))
+
+(deftest put-library-path-test
+ (testing "PUT /api/ee/transforms-python/library/:path"
+ (mt/with-premium-features #{:transforms-python}
+ (testing "requires superuser permissions"
+ (is (= "You don't have permissions to do that."
+ (mt/user-http-request :rasta :put 403 "ee/transforms-python/library/common"
+ {:source "def test(): pass"}))))
+
+ (testing "validates request body"
+ (testing "requires source field"
+ (is (=? {:errors
+ {:source "string"}}
+ (mt/user-http-request :crowberto :put 400 "ee/transforms-python/library/common"
+ {}))))
+
+ (testing "allows empty string"
+ (t2/delete! :model/PythonLibrary)
+ (is (=? {:source ""
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (mt/user-http-request :crowberto :put 200 "ee/transforms-python/library/common"
+ {:source ""})))))
+
+ (testing "creates new library when none exists"
+ (t2/delete! :model/PythonLibrary)
+ (is (=? {:source "def new_function():\n return 100"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (mt/user-http-request :crowberto :put 200 "ee/transforms-python/library/common"
+ {:source "def new_function():\n return 100"})))
+ (is (= "def new_function():\n return 100"
+ (t2/select-one-fn :source :model/PythonLibrary))))
+
+ (testing "updates existing library"
+ (t2/delete! :model/PythonLibrary)
+ (python-library/update-python-library-source! "common" "def old_function():\n return 1")
+ (is (=? {:source "def updated_function():\n return 2"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (mt/user-http-request :crowberto :put 200 "ee/transforms-python/library/common"
+ {:source "def updated_function():\n return 2"})))
+ (is (= "def updated_function():\n return 2"
+ (t2/select-one-fn :source :model/PythonLibrary)))
+ (is (= 1 (t2/count :model/PythonLibrary)) "Should not create duplicate records"))
+
+ (testing "rejects invalid paths"
+ (is (= "Invalid library path. Only 'common' is currently supported."
+ (:message (mt/user-http-request :crowberto :put 400 "ee/transforms-python/library/invalid-path"
+ {:source "def test(): pass"}))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/transforms_python/models/python_library_test.clj b/enterprise/backend/test/metabase_enterprise/transforms_python/models/python_library_test.clj
new file mode 100644
index 00000000000..11a19f18ed4
--- /dev/null
+++ b/enterprise/backend/test/metabase_enterprise/transforms_python/models/python_library_test.clj
@@ -0,0 +1,78 @@
+(ns metabase-enterprise.transforms-python.models.python-library-test
+ (:require
+ [clojure.test :refer :all]
+ [metabase-enterprise.transforms-python.models.python-library :as python-library]
+ [toucan2.core :as t2]))
+
+(set! *warn-on-reflection* true)
+
+(deftest update-python-library-source-test
+ (testing "update-python-library-source!"
+ (testing "creates new record when none exists"
+ (t2/delete! :model/PythonLibrary)
+ (is (=? {:source "def new_func(): return 1"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (python-library/update-python-library-source! "common" "def new_func(): return 1")))
+ (is (= 1 (t2/count :model/PythonLibrary)))
+ (is (= "def new_func(): return 1"
+ (t2/select-one-fn :source :model/PythonLibrary))))
+
+ (testing "updates existing record"
+ (is (= 1 (t2/count :model/PythonLibrary)))
+ (is (=? {:source "def updated_func(): return 2"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (python-library/update-python-library-source! "common" "def updated_func(): return 2")))
+ (is (= 1 (t2/count :model/PythonLibrary)) "Should not create duplicate")
+ (is (= "def updated_func(): return 2"
+ (t2/select-one-fn :source :model/PythonLibrary))))
+
+ (testing "rejects invalid paths"
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo
+ #"Invalid library path"
+ (python-library/update-python-library-source! "invalid-path" "def test(): pass")))
+ (is (= 1 (t2/count :model/PythonLibrary)) "Should not create library with invalid path"))))
+
+(deftest get-python-library-by-path-test
+ (testing "get-python-library-by-path"
+ (testing "returns library when path is valid"
+ (t2/delete! :model/PythonLibrary)
+ (python-library/update-python-library-source! "common" "def test(): pass")
+ (is (=? {:source "def test(): pass"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (python-library/get-python-library-by-path "common"))))
+
+ (testing "rejects invalid paths"
+ (is (thrown-with-msg? clojure.lang.ExceptionInfo
+ #"Invalid library path"
+ (python-library/get-python-library-by-path "invalid-path"))))))
+
+(deftest normalize-path-test
+ (testing "normalize-path function"
+ (testing "adds .py extension when missing"
+ (is (= "common.py" (#'python-library/normalize-path "common"))))
+
+ (testing "doesn't duplicate .py extension"
+ (is (= "common.py" (#'python-library/normalize-path "common.py"))))
+
+ (testing "works with paths that already have .py extension when updating"
+ (t2/delete! :model/PythonLibrary)
+ (python-library/update-python-library-source! "common.py" "def test(): pass")
+ (is (=? {:source "def test(): pass"
+ :path "common.py"
+ :id integer?
+ :created_at some?
+ :updated_at some?}
+ (python-library/get-python-library-by-path "common.py")))
+ ;; Verify we can also access it without .py
+ (is (=? {:source "def test(): pass"
+ :path "common.py"}
+ (python-library/get-python-library-by-path "common"))))))
diff --git a/resources/migrations/057_update_migrations.yaml b/resources/migrations/057_update_migrations.yaml
index 81d0e4dac6d..d1900c08cba 100644
--- a/resources/migrations/057_update_migrations.yaml
+++ b/resources/migrations/057_update_migrations.yaml
@@ -1353,6 +1353,52 @@ databaseChangeLog:
name: comment_id
rollback: # will be removed along the table
+ - changeSet:
+ id: v57.2025-09-11T10:00:00
+ author: qnkhuat
+ comment: Add python_library table for storing Python transform user modules
+ changes:
+ - createTable:
+ tableName: python_library
+ remarks: Store Python library code for user modules in transforms
+ columns:
+ - column:
+ name: id
+ type: integer
+ autoIncrement: true
+ remarks: Primary key for python_library
+ constraints:
+ primaryKey: true
+ primaryKeyName: pk_python_library
+ - column:
+ name: path
+ type: varchar(254)
+ remarks: Path identifier for the library
+ constraints:
+ nullable: false
+ unique: true
+ uniqueConstraintName: uk_python_library_path
+ - column:
+ name: source
+ type: ${text.type}
+ remarks: Python source code for user modules
+ constraints:
+ nullable: true
+ - column:
+ name: created_at
+ type: ${timestamp_type}
+ remarks: When the record was created
+ constraints:
+ nullable: false
+ defaultValueComputed: current_timestamp
+ - column:
+ name: updated_at
+ type: ${timestamp_type}
+ remarks: When the record was last updated
+ constraints:
+ nullable: false
+ defaultValueComputed: current_timestamp
+
# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<
########################################################################################################################
diff --git a/src/metabase/models/resolution.clj b/src/metabase/models/resolution.clj
index b0195e771e9..da883baffea 100644
--- a/src/metabase/models/resolution.clj
+++ b/src/metabase/models/resolution.clj
@@ -68,6 +68,7 @@
:model/PermissionsGroupMembership metabase.permissions.models.permissions-group-membership
:model/PermissionsRevision metabase.permissions.models.permissions-revision
:model/PersistedInfo metabase.model-persistence.models.persisted-info
+ :model/PythonLibrary metabase-enterprise.transforms-python.models.python-library
:model/Pulse metabase.pulse.models.pulse
:model/PulseCard metabase.pulse.models.pulse-card
:model/PulseChannel metabase.pulse.models.pulse-channel
diff --git a/test/metabase/cmd/copy_test.clj b/test/metabase/cmd/copy_test.clj
index 23700f2ed52..2725594cf97 100644
--- a/test/metabase/cmd/copy_test.clj
+++ b/test/metabase/cmd/copy_test.clj
@@ -32,6 +32,7 @@
:model/ContentTranslation
:model/DashboardFavorite
:model/DatabaseRouter
+ :model/PythonLibrary
:model/Query
:model/QueryCache
:model/QueryExecution