The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Don't cascade delete transform runs on transform delete (#68642)
Nathan Voxlandd1e940e66b54
diff --git a/enterprise/backend/src/metabase_enterprise/transforms/models/transform.clj b/enterprise/backend/src/metabase_enterprise/transforms/models/transform.cljindex ea48b8a3b9b..d4a37728dc3 100644--- a/enterprise/backend/src/metabase_enterprise/transforms/models/transform.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms/models/transform.clj@@ -18,7 +18,8 @@[metabase.search.spec :as search.spec][metabase.util :as u][methodical.core :as methodical]- [toucan2.core :as t2]))+ [toucan2.core :as t2]+ [toucan2.instance :as t2.instance]))(set! *warn-on-reflection* true)@@ -121,13 +122,21 @@transform))(methodical/defmethod t2/batched-hydrate [:model/TransformRun :transform]- "Add transform to a TransformRun"+ "Add transform to a TransformRun. For orphaned runs (where transform was deleted),+ returns a map with :name from the denormalized transform_name and :deleted true."[_model _k runs](if-not (seq runs)runs- (let [transform-ids (into #{} (map :transform_id) runs)- id->transform (t2/select-pk->fn identity [:model/Transform :id :name] :id [:in transform-ids])]- (for [run runs] (assoc run :transform (get id->transform (:transform_id run)))))))+ (let [transform-ids (into #{} (keep :transform_id) runs)+ id->transform (when (seq transform-ids)+ (t2/select-pk->fn identity [:model/Transform :id :name] :id [:in transform-ids]))]+ (for [run runs]+ (assoc run :transform+ (if-let [transform-id (:transform_id run)]+ (get id->transform transform-id)+ ;; Orphaned run - use denormalized transform_name+ (when-let [name (:transform_name run)]+ (t2.instance/instance :model/Transform {:name name :deleted true}))))))))(methodical/defmethod t2/batched-hydrate [:model/Transform :last_run]"Add last_run to a transform"diff --git a/enterprise/backend/src/metabase_enterprise/transforms/models/transform_run.clj b/enterprise/backend/src/metabase_enterprise/transforms/models/transform_run.cljindex 1138609b41d..af3bc4bcef7 100644--- a/enterprise/backend/src/metabase_enterprise/transforms/models/transform_run.clj+++ b/enterprise/backend/src/metabase_enterprise/transforms/models/transform_run.clj@@ -56,13 +56,17 @@(defn start-run!"Start a run. If `user_id` is provided in properties, it will be stored with the run- and used for attribution in the audit log (avoiding 'External user' for scheduled runs)."+ and used for attribution in the audit log (avoiding 'External user' for scheduled runs).+ Also captures `transform_name` and `transform_entity_id` for historical reference."([transform-id](start-run! transform-id {}))([transform-id properties]- (let [run (t2/insert-returning-instance! :model/TransformRun+ (let [transform (t2/select-one [:model/Transform :name :entity_id] :id transform-id)+ run (t2/insert-returning-instance! :model/TransformRun(assoc properties:transform_id transform-id+ :transform_name (:name transform)+ :transform_entity_id (:entity_id transform):status :started:is_active true))];; Pass user_id to the event so audit log properly attributes the rundiff --git a/enterprise/backend/test/metabase_enterprise/transforms/models_test.clj b/enterprise/backend/test/metabase_enterprise/transforms/models_test.cljindex a844cf0132e..98ee11f0b8c 100644--- a/enterprise/backend/test/metabase_enterprise/transforms/models_test.clj+++ b/enterprise/backend/test/metabase_enterprise/transforms/models_test.clj@@ -4,6 +4,7 @@[clojure.test :refer :all][metabase-enterprise.transforms.models.transform :as transform.model][metabase-enterprise.transforms.models.transform-job :as transform-job]+ [metabase-enterprise.transforms.models.transform-run :as transform-run][metabase-enterprise.transforms.models.transform-tag :as transform-tag][metabase.collections.models.collection :as collection][metabase.config.core :as config]@@ -342,3 +343,43 @@(t2/insert! :model/Card (merge (mt/with-temp-defaults :model/Card) {:type :model :collection_id (:id transforms)}))))(is (thrown-with-msg? clojure.lang.ExceptionInfo #"A Transform can only go in Collections in the :transforms namespace."(t2/insert! :model/Transform (assoc (mt/with-temp-defaults :model/Transform) :collection_id (:id regular-col))))))))))++(deftest deleted-transform-preserves-runs-test+ (testing "Deleting a transform sets transform_id to NULL but preserves the run"+ (mt/with-premium-features #{:transforms}+ (mt/with-temp [:model/Transform {transform-id :id+ transform-name :name+ entity-id :entity_id} {}+ :model/TransformRun {run-id :id} {:transform_id transform-id+ :transform_name transform-name+ :transform_entity_id entity-id+ :status "succeeded"+ :run_method "manual"}]+ (t2/delete! :model/Transform :id transform-id)++ (let [run (t2/select-one :model/TransformRun :id run-id)]+ (is (some? run))+ (is (nil? (:transform_id run)))+ (is (= transform-name (:transform_name run)))+ (is (= entity-id (:transform_entity_id run))))))))++(deftest orphaned-run-hydration-test+ (testing "Hydrating :transform on orphaned runs returns {:name ... :deleted true}"+ (mt/with-premium-features #{:transforms}+ (mt/with-temp [:model/TransformRun run {:transform_id nil+ :transform_name "Deleted Transform"+ :transform_entity_id "test-entity-id-123"+ :status "succeeded"+ :run_method "manual"}]+ (let [hydrated (t2/hydrate run :transform)]+ (is (= {:name "Deleted Transform" :deleted true} (:transform hydrated))))))))++(deftest start-run-captures-transform-info-test+ (testing "start-run! captures transform_name and transform_entity_id"+ (mt/with-premium-features #{:transforms}+ (mt/with-temp [:model/Transform {transform-id :id+ transform-name :name+ entity-id :entity_id} {}]+ (let [run (transform-run/start-run! transform-id {:run_method "manual"})]+ (is (= transform-name (:transform_name run)))+ (is (= entity-id (:transform_entity_id run))))))))diff --git a/enterprise/frontend/src/metabase-enterprise/api/transform.ts b/enterprise/frontend/src/metabase-enterprise/api/transform.tsindex 5f02a4761b7..ee762820064 100644--- a/enterprise/frontend/src/metabase-enterprise/api/transform.ts+++ b/enterprise/frontend/src/metabase-enterprise/api/transform.ts@@ -72,7 +72,11 @@ export const transformApi = EnterpriseApi.injectEndpoints({url: `/api/ee/transform/${id}/run`,}),invalidatesTags: (_, error, id) =>- invalidateTags(error, [idTag("transform", id), tag("table")]),+ invalidateTags(error, [+ idTag("transform", id),+ tag("table"),+ listTag("transform-run"),+ ]),onQueryStarted: async (id, { dispatch, queryFulfilled }) => {const patchResult = dispatch(transformApi.util.updateQueryData("getTransform", id, (draft) => {@@ -191,8 +195,8 @@ export const transformApi = EnterpriseApi.injectEndpoints({method: "DELETE",url: `/api/ee/transform/${id}`,}),- invalidatesTags: (_, error) =>- invalidateTags(error, [listTag("transform")]),+ invalidatesTags: (_, error, id) =>+ invalidateTags(error, [listTag("transform"), idTag("transform", id)]),}),deleteTransformTarget: builder.mutation<void, TransformId>({query: (id) => ({diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.module.css b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.module.cssindex f508fd8d425..0ade54b1da9 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.module.css+++ b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.module.css@@ -2,6 +2,14 @@cursor: pointer;}+.deletedRow {+ cursor: default;+}++.deletedRow:hover {+ background-color: inherit;+}+.wrap {overflow-wrap: anywhere;}diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.tsxindex 9fcd48b4575..420b238f928 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.tsx@@ -1,3 +1,4 @@+import cx from "classnames";import { push } from "react-router-redux";import { t } from "ttag";@@ -6,7 +7,7 @@ import { PaginationControls } from "metabase/common/components/PaginationControlimport { useSetting } from "metabase/common/hooks";import { useDispatch } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";-import { Card, Flex, Group, Stack } from "metabase/ui";+import { Card, Flex, Group, Stack, Text, Tooltip } from "metabase/ui";import type { TransformRun, TransformTag } from "metabase-types/api";import { ListEmptyState } from "../../../components/ListEmptyState";@@ -68,7 +69,7 @@ function RunTable({ runs, tags }: RunTableProps) {const dispatch = useDispatch();const handleRowClick = (run: TransformRun) => {- if (run.transform) {+ if (run.transform && !run.transform.deleted) {dispatch(push(Urls.transform(run.transform.id)));}};@@ -91,48 +92,68 @@ function RunTable({ runs, tags }: RunTableProps) {t`Tags`,]}>- {runs.map((run) => (- <tr- key={run.id}- className={S.row}- onClick={() => handleRowClick(run)}- >- <td className={S.wrap}>{run.transform?.name}</td>- <td className={S.nowrap}>- {parseTimestampWithTimezone(- run.start_time,- systemTimezone,- ).format("lll")}- </td>- <td className={S.nowrap}>- {run.end_time- ? parseTimestampWithTimezone(- run.end_time,- systemTimezone,- ).format("lll")- : null}- </td>- <td className={S.wrap}>- <RunStatusInfo- transform={run.transform}- status={run.status}- message={run.message}- endTime={- run.end_time != null- ? parseTimestampWithTimezone(- run.end_time,- systemTimezone,- ).toDate()- : null- }- />- </td>- <td className={S.wrap}>{formatRunMethod(run.run_method)}</td>- <td className={S.wrap}>- <TagList tags={tags} tagIds={run.transform?.tag_ids ?? []} />- </td>- </tr>- ))}+ {runs.map((run) => {+ const isTransformDeleted = run.transform?.deleted === true;+ const transformName = run.transform?.name || t`Unnamed transform`;++ return (+ <tr+ key={run.id}+ className={cx(S.row, { [S.deletedRow]: isTransformDeleted })}+ onClick={() => handleRowClick(run)}+ >+ <td className={S.wrap}>+ {isTransformDeleted ? (+ <Tooltip label={t`${transformName} has been deleted`}>+ <Text+ c="text-tertiary"+ component="span"+ display="inline"+ fs="italic"+ >+ {transformName}+ </Text>+ </Tooltip>+ ) : (+ transformName+ )}+ </td>+ <td className={S.nowrap}>+ {parseTimestampWithTimezone(+ run.start_time,+ systemTimezone,+ ).format("lll")}+ </td>+ <td className={S.nowrap}>+ {run.end_time+ ? parseTimestampWithTimezone(+ run.end_time,+ systemTimezone,+ ).format("lll")+ : null}+ </td>+ <td className={S.wrap}>+ <RunStatusInfo+ transform={run.transform}+ status={run.status}+ message={run.message}+ endTime={+ run.end_time != null+ ? parseTimestampWithTimezone(+ run.end_time,+ systemTimezone,+ ).toDate()+ : null+ }+ />+ </td>+ <td className={S.wrap}>{formatRunMethod(run.run_method)}</td>+ <td className={S.wrap}>+ <TagList tags={tags} tagIds={run.transform?.tag_ids ?? []} />+ </td>+ </tr>+ );+ })}</AdminContentTable></Card>);diff --git a/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.unit.spec.tsxnew file mode 100644index 00000000000..4a452ad1e8e--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/transforms/pages/RunListPage/RunList/RunList.unit.spec.tsx@@ -0,0 +1,91 @@+import userEvent from "@testing-library/user-event";+import { Route } from "react-router";++import { renderWithProviders, screen } from "__support__/ui";+import type { TransformRun } from "metabase-types/api";+import {+ createMockTransform,+ createMockTransformRun,+} from "metabase-types/api/mocks";++import { RunList } from "./RunList";++type SetupOpts = {+ runs?: TransformRun[];+};++function setup({ runs = [] }: SetupOpts = {}) {+ return renderWithProviders(+ <>+ <Route+ path="/data-studio/transforms/runs"+ component={() => (+ <RunList params={{}} runs={runs} tags={[]} totalCount={runs.length} />+ )}+ />+ <Route+ path="/data-studio/transforms/:id"+ component={() => <div data-testid="transform-detail" />}+ />+ </>,+ {+ initialRoute: "/data-studio/transforms/runs",+ withRouter: true,+ },+ );+}++describe("RunList", () => {+ it("should render transform name", () => {+ const transform = createMockTransform({ name: "My Transform" });+ const run = createMockTransformRun({ transform });+ setup({ runs: [run] });++ expect(screen.getByText("My Transform")).toBeInTheDocument();+ });++ it("should navigate to transform detail when clicking a row", async () => {+ const transform = createMockTransform({ id: 123, name: "Test Transform" });+ const run = createMockTransformRun({ transform });+ const { history } = setup({ runs: [run] });++ const row = screen.getByRole("row", { name: /Test Transform/ });+ await userEvent.click(row);++ expect(history?.getCurrentLocation()?.pathname).toBe(+ "/data-studio/transforms/123",+ );+ expect(screen.getByTestId("transform-detail")).toBeInTheDocument();+ });++ describe("deleted transforms", () => {+ it("should show deleted indicator for deleted transforms", () => {+ const transform = createMockTransform({+ name: "Deleted Transform",+ deleted: true,+ });+ const run = createMockTransformRun({ transform });+ setup({ runs: [run] });++ expect(screen.getByText("Deleted Transform")).toBeInTheDocument();+ });++ it("should not navigate when clicking a row with deleted transform", async () => {+ const transform = createMockTransform({+ id: 456,+ name: "Deleted Transform",+ deleted: true,+ });+ const run = createMockTransformRun({ transform });+ const { history } = setup({ runs: [run] });++ const row = screen.getByRole("row", { name: /Deleted Transform/ });+ await userEvent.click(row);++ expect(history?.getCurrentLocation()?.pathname).toBe(+ "/data-studio/transforms/runs",+ );+ expect(screen.queryByTestId("transform-detail")).not.toBeInTheDocument();+ });+ });+});diff --git a/frontend/src/metabase-types/api/transform.ts b/frontend/src/metabase-types/api/transform.tsindex 98003368db1..86dcc24dc4c 100644--- a/frontend/src/metabase-types/api/transform.ts+++ b/frontend/src/metabase-types/api/transform.ts@@ -27,6 +27,9 @@ export type Transform = {updated_at: string;source_readable: boolean;+ // true when transform was deleted but still referenced by runs+ deleted?: boolean;+// creator fieldscreator_id?: UserId;diff --git a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsxindex e3072ac4db4..999168f0d73 100644--- a/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx+++ b/frontend/src/metabase/nav/components/search/SearchBar/SearchBar.styled.tsx@@ -40,6 +40,7 @@ export const SearchInputContainer = styled.div<{}return css`background-color: var(--mb-color-background-primary);+&:hover {background-color: var(--mb-color-background-secondary);}diff --git a/resources/migrations/059_update_migrations.yaml b/resources/migrations/059_update_migrations.yamlindex e3b86329b8c..8b7264ca788 100644--- a/resources/migrations/059_update_migrations.yaml+++ b/resources/migrations/059_update_migrations.yaml@@ -801,6 +801,88 @@ databaseChangeLog:sql: INSERT INTO python_library (path, source) VALUES ('common.py', '')rollback:+ - changeSet:+ id: v59.2026-01-23T13:00:00+ author: nvoxland+ comment: Add transform_name for preserving history when transform is deleted+ changes:+ - addColumn:+ tableName: transform_run+ columns:+ - column:+ name: transform_name+ type: varchar(254)+ remarks: Name of transform at time of run, stored for historical purposes++ - changeSet:+ id: v59.2026-01-23T13:00:01+ author: nvoxland+ comment: Add transform_entity_id column for potential reconnection when transform is recreated+ changes:+ - addColumn:+ tableName: transform_run+ columns:+ - column:+ name: transform_entity_id+ type: char(21)+ remarks: Original transform entity_id, stored for historical purposes++ - changeSet:+ id: v59.2026-01-23T13:00:02+ author: nvoxland+ comment: Backfill transform_name and transform_entity_id for existing runs+ changes:+ - sql:+ sql: >-+ UPDATE transform_run+ SET transform_name = (SELECT name FROM transform WHERE transform.id = transform_run.transform_id),+ transform_entity_id = (SELECT entity_id FROM transform WHERE transform.id = transform_run.transform_id)+ rollback:+ - sql:+ sql: >-+ UPDATE transform_run SET transform_name = NULL, transform_entity_id = NULL++ - changeSet:+ id: v59.2026-01-23T13:00:03+ author: nvoxland+ comment: Drop existing FK constraint on transform_run.transform_id to change to SET NULL behavior+ changes:+ - dropForeignKeyConstraint:+ baseTableName: transform_run+ constraintName: fk_transform_run_transform_id+ rollback:+ - addForeignKeyConstraint:+ baseTableName: transform_run+ baseColumnNames: transform_id+ referencedTableName: transform+ referencedColumnNames: id+ constraintName: fk_transform_run_transform_id+ onDelete: CASCADE++ - changeSet:+ id: v59.2026-01-23T13:00:04+ author: nvoxland+ comment: Make transform_id nullable to support orphaned runs when transform is deleted+ changes:+ - dropNotNullConstraint:+ tableName: transform_run+ columnName: transform_id+ columnDataType: int++ - changeSet:+ id: v59.2026-01-23T13:00:05+ author: nvoxland+ comment: Re-add FK constraint with ON DELETE SET NULL behavior to preserve runs when transform is deleted+ changes:+ - addForeignKeyConstraint:+ baseTableName: transform_run+ baseColumnNames: transform_id+ referencedTableName: transform+ referencedColumnNames: id+ constraintName: fk_transform_run_transform_id+ onDelete: SET NULL++- changeSet:id: v59.2026-01-27T12:00:00author: epaget