Skip to content

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

Python test runs on the BE test runner (#64695)

Romeo Van Snick1c4435c17e4a
diff --git a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
index bf755a0454e..4743481da0b 100644
--- a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
@@ -1559,11 +1559,12 @@ LIMIT
H.PythonEditor.clear().type(
dedent`
- import pandas as pd
+ import pandas as pd
- def transform():
- return pd.DataFrame([{"foo": common.useful_calculation(1, 2)}])
- `,
+ def transform():
+ return pd.DataFrame([{"foo": common.useful_calculation(1, 2)}])
+ `,
+ { allowFastSet: true },
);
getQueryEditor().findByLabelText("Import common library").click();
@@ -2674,6 +2675,77 @@ describe("scenarios > admin > transforms > runs", () => {
});
});
+describe(
+ "scenarios > admin > transforms > python runner",
+ { tags: ["@python"] },
+ () => {
+ beforeEach(() => {
+ H.restore("postgres-writable");
+ H.resetTestTable({ type: "postgres", table: "many_schemas" });
+ H.resetSnowplow();
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });
+
+ setPythonRunnerSettings();
+ });
+
+ afterEach(() => {
+ H.expectNoBadSnowplowEvents();
+ });
+
+ it("should be possible to test run a Python script", () => {
+ H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(
+ (id) => {
+ createPythonLibrary(
+ "common.py",
+ dedent`
+ def useful_calculation(a, b):
+ return a + b
+ `,
+ );
+
+ createPythonTransform({
+ body: dedent`
+ import pandas as pd
+ import common
+
+
+ def transform(foo):
+ print("Hello, world!")
+ return pd.DataFrame([{"foo": common.useful_calculation(40, 2) }])
+ `,
+ sourceTables: { foo: id },
+ visitTransform: true,
+ });
+ },
+ );
+
+ cy.log("running the script should work");
+ runPythonScriptAndWaitForSuccess();
+ H.assertTableData({
+ columns: ["foo"],
+ firstRows: [["42"]],
+ });
+
+ cy.log("updating the common library should affect the results");
+ createPythonLibrary(
+ "common.py",
+ dedent`
+ def useful_calculation(a, b):
+ return a + b + 1
+ `,
+ );
+
+ runPythonScriptAndWaitForSuccess();
+ H.assertTableData({
+ columns: ["foo"],
+ firstRows: [["43"]],
+ });
+ });
+ },
+);
+
describe("scenarios > admin > transforms", () => {
beforeEach(() => {
H.restore();
@@ -2968,6 +3040,16 @@ function setPythonRunnerSettings() {
H.updateEnterpriseSetting("python-storage-s-3-path-style-access", true);
}
+function runPythonScriptAndWaitForSuccess() {
+ getQueryEditor().findByTestId("run-button").click();
+
+ getQueryEditor()
+ .findByTestId("loading-indicator", { timeout: 60000 })
+ .should("not.exist");
+
+ cy.findByTestId("python-results").should("be.visible");
+}
+
function getRowNames(): Cypress.Chainable<string[]> {
return getTransformsList()
.findAllByTestId("tree-node-name")
diff --git a/enterprise/frontend/src/metabase-enterprise/api/transform-python.ts b/enterprise/frontend/src/metabase-enterprise/api/transform-python.ts
index cdfe5dde0ac..4dc544237b1 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/transform-python.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/transform-python.ts
@@ -1,6 +1,6 @@
import type {
- ExecutePythonTransformRequest,
- ExecutePythonTransformResponse,
+ TestPythonTransformRequest,
+ TestPythonTransformResponse,
} from "metabase-types/api";
import { EnterpriseApi } from "./api";
@@ -8,27 +8,20 @@ import { EnterpriseApi } from "./api";
export const pythonRunnerApi = EnterpriseApi.injectEndpoints({
endpoints: (builder) => ({
executePython: builder.mutation<
- ExecutePythonTransformResponse,
- ExecutePythonTransformRequest
+ TestPythonTransformResponse,
+ TestPythonTransformRequest
>({
- query: ({ code, tables }) => ({
- url: "/api/ee/transform/test-python",
+ query: ({ code, source_tables }) => ({
+ url: "/api/ee/transforms-python/test-run",
method: "POST",
body: {
code,
- tables,
+ source_tables,
},
}),
}),
- cancelPython: builder.mutation<void, void>({
- query: () => ({
- url: "/api/ee/transform/test-python/cancel",
- method: "POST",
- }),
- }),
}),
overrideExisting: true,
});
-export const { useExecutePythonMutation, useCancelPythonMutation } =
- pythonRunnerApi;
+export const { useExecutePythonMutation } = pythonRunnerApi;
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
index e2ca654d3af..e7ed914c49a 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorBody/PythonEditorBody.tsx
@@ -93,18 +93,14 @@ export function PythonEditorBody({
</Tooltip>
</>
)}
- {withDebugger && (
- <Box p="md">
- <RunButtonWithTooltip
- disabled={!isRunnable}
- isRunning={isRunning}
- isDirty={isDirty}
- onRun={onRun}
- onCancel={onCancel}
- getTooltip={() => t`Run Python script`}
- />
- </Box>
- )}
+ <RunButtonWithTooltip
+ disabled={!isRunnable}
+ isRunning={isRunning}
+ isDirty={isDirty}
+ onRun={onRun}
+ onCancel={onCancel}
+ getTooltip={() => t`Run Python script`}
+ />
</Stack>
<SharedLibraryActions source={source} onChange={onChange} />
</Flex>
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/ExecutionOutputTable.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/ExecutionOutputTable.tsx
index 035c567ef4c..e62538c281c 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/ExecutionOutputTable.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/ExecutionOutputTable.tsx
@@ -1,23 +1,33 @@
-import { useMemo } from "react";
-
import { DataGrid, useDataGridInstance } from "metabase/data-grid";
+import { formatValue } from "metabase/lib/formatting";
+import type { RowValue, TestPythonTransformResponse } from "metabase-types/api";
-import { type Row, parseOutput } from "./utils";
+export type Row = Record<string, RowValue>;
-export function ExecutionOutputTable({ output }: { output?: string }) {
- const { headers, rows } = useMemo(() => parseOutput(output ?? ""), [output]);
+export function ExecutionOutputTable({
+ output,
+}: {
+ output?: TestPythonTransformResponse["output"];
+}) {
+ const { cols = [], rows = [] } = output ?? {};
const tableProps = useDataGridInstance<Row, unknown>({
data: rows,
- columnsOptions: headers.map((header) => ({
- id: header,
- name: header,
- accessorFn: (row) => row[header],
+ columnsOptions: cols.map((column) => ({
+ id: column.name,
+ name: column.name,
+ accessorFn: (row) => row[column.name],
+ formatter: (value) => {
+ return formatValue(value, {
+ type: "cell",
+ jsx: true,
+ rich: true,
+ });
+ },
})),
- minGridWidth: 100,
});
- if (!output || headers.length === 0) {
+ if (!output || cols.length === 0) {
return null;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css
index c24311c31c2..3b752132b61 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css
@@ -1,7 +1,12 @@
+.header {
+ border-top: 1px solid var(--mb-color-border);
+ border-bottom: 1px solid var(--mb-color-border);
+}
+
.logs {
white-space: pre;
- border: 1px solid var(--mb-color-border);
font-family: var(--mb-default-monospace-font-family);
+ overflow: auto;
}
.visualization {
@@ -15,10 +20,6 @@
border-radius: var(--mantine-radius-md);
}
-.empty {
- border-top: 1px solid var(--mb-color-border);
-}
-
.tableHeader {
background-color: var(--mb-color-bg-light);
padding: var(--mantine-spacing-sm);
@@ -29,23 +30,6 @@
padding: var(--mantine-spacing-sm);
}
-.error {
- color: var(--mb-color-error);
- background-color: var(--mb-color-background-error);
- border-bottom: 1px solid var(--mb-color-border);
-}
-
-.info {
- color: var(--mb-color-text-dark);
- border: 1px solid var(--mb-color-bg-medium);
- background-color: var(--mb-color-bg-light);
-}
-
-.success {
- color: var(--mb-color-success);
- border-bottom: 1px solid var(--mb-color-border);
-}
-
.loading {
position: absolute;
top: 0;
@@ -54,3 +38,13 @@
right: 0;
background-color: rgba(255, 255, 255, 0.5);
}
+
+.error {
+ background-color: var(--mb-color-bg-error);
+}
+
+.traceback {
+ white-space: pre;
+ font-family: var(--mb-default-monospace-font-family);
+ overflow: auto;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx
index 94f4f9034b5..b7ce58e8d7b 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx
@@ -1,42 +1,86 @@
-import type { ReactNode } from "react";
+import { useState } from "react";
import { c, t } from "ttag";
import EmptyCodeResult from "assets/img/empty-states/code.svg";
+import { AnsiLogs } from "metabase/common/components/AnsiLogs";
import DebouncedFrame from "metabase/common/components/DebouncedFrame";
import { LoadingSpinner } from "metabase/common/components/MetadataInfo/MetadataInfo.styled";
import { isMac } from "metabase/lib/browser";
-import { Box, Flex, Icon, Stack, Text, Title } from "metabase/ui";
-
-import type { ExecutionResult } from "../utils";
+import { Box, Flex, Group, Icon, Stack, Tabs, Text } from "metabase/ui";
+import type { TestPythonTransformResponse } from "metabase-types/api";
import { ExecutionOutputTable } from "./ExecutionOutputTable";
import S from "./PythonEditorResults.module.css";
type PythonEditorProps = {
isRunning?: boolean;
- executionResult?: ExecutionResult | null;
+ executionResult: TestPythonTransformResponse;
};
+type ResultsTab = "results" | "output";
+
export function PythonEditorResults({
executionResult,
isRunning,
}: PythonEditorProps) {
+ const [tab, setTab] = useState<ResultsTab>("results");
+ const hasDataOrError = executionResult?.output || executionResult?.error;
return (
<DebouncedFrame className={S.visualization}>
- <ExecutionResultHeader executionResult={executionResult} />
- <ExecutionResults executionResult={executionResult} />
- {isRunning && <LoadingState />}
+ <Stack data-testid="python-results" gap={0} h="100%">
+ <ExecutionResultHeader
+ executionResult={executionResult}
+ tab={tab}
+ onTabChange={setTab}
+ />
+ {!hasDataOrError && <EmptyState />}
+ {hasDataOrError &&
+ tab === "results" &&
+ (executionResult?.error ? (
+ <ErrorState error={executionResult.error.message} />
+ ) : (
+ <ExecutionOutputTable output={executionResult?.output} />
+ ))}
+ {executionResult && tab === "output" && (
+ <ExecutionOutputLogs executionResult={executionResult} />
+ )}
+ {isRunning && <LoadingState />}
+ </Stack>
</DebouncedFrame>
);
}
function ExecutionResultHeader({
executionResult,
+ tab,
+ onTabChange,
}: {
- executionResult?: ExecutionResult | null;
+ executionResult?: TestPythonTransformResponse | null;
+ tab: ResultsTab;
+ onTabChange: (tab: ResultsTab) => void;
}) {
const message = getMessageForExecutionResult(executionResult);
- return <Flex w="100%">{message}</Flex>;
+
+ return (
+ <Group className={S.header} justify="space-between">
+ <Box mt="xs">
+ <Tabs
+ value={tab}
+ onChange={(value) => {
+ if (value) {
+ onTabChange(value as ResultsTab);
+ }
+ }}
+ >
+ <Tabs.List>
+ <Tabs.Tab value="results">{t`Results`}</Tabs.Tab>
+ <Tabs.Tab value="output">{t`Output`}</Tabs.Tab>
+ </Tabs.List>
+ </Tabs>
+ </Box>
+ {message}
+ </Group>
+ );
}
function getRunQueryShortcut() {
@@ -55,7 +99,7 @@ function EmptyState() {
const keyboardShortcut = getRunQueryShortcut();
return (
- <Flex h="100%" align="center" justify="center" className={S.empty}>
+ <Flex h="100%" align="center" justify="center">
<Stack maw="25rem" gap={0} ta="center" align="center">
<Box maw="3rem" mb="0.75rem">
<img src={EmptyCodeResult} alt="Code prompt icon" />
@@ -71,105 +115,56 @@ function EmptyState() {
);
}
-function ExecutionResults({
- executionResult,
-}: {
- executionResult?: ExecutionResult | null;
-}) {
- if (!executionResult) {
- return <EmptyState />;
- }
-
+function ErrorState({ error }: { error: string }) {
return (
- <Stack gap={0}>
- <ExecutionLogs
- label={t`Standard output:`}
- content={executionResult.stdout}
- />
- <ExecutionLogs
- label={t`Standard error:`}
- content={executionResult.stderr}
- />
-
- <ExecutionOutputTable output={executionResult.output} />
+ <Stack gap="sm" h="100%" p="md" c="error" className={S.error}>
+ <Group fw="bold" gap="sm">
+ <Icon name="warning" />
+ {t`Error`}
+ </Group>
+ <Box className={S.traceback} fz="sm">
+ {error}
+ </Box>
</Stack>
);
}
function getMessageForExecutionResult(
- executionResult?: ExecutionResult | null,
+ executionResult?: TestPythonTransformResponse | null,
) {
if (!executionResult) {
return null;
}
- if (executionResult.error) {
- return (
- <Box className={S.error} p="sm" w="100%">
- <Flex gap="sm">
- <Icon name="warning" />
- <Stack gap={0}>
- <Title order={5} mb="xs">
- {t`An error occurred while executing your Python script`}
- </Title>
- {executionResult.error}
- </Stack>
- </Flex>
- </Box>
- );
- }
- if (!executionResult.output) {
+ if (executionResult.error) {
return (
- <Flex className={S.info} p="sm" gap="sm" align="center" w="100%">
- <Icon name="info" />
- {t`No results to display.`}
+ <Flex gap="sm" align="center" pr="md" c="error">
+ <Icon name="warning" />
+ {t`An error occurred while executing your Python script`}
</Flex>
);
}
return (
- <Flex className={S.success} p="sm" gap="sm" align="center" w="100%">
- <Icon name="check" />
- {t`Script executed successfully.`}
+ <Flex gap="sm" align="center" pr="md" c="success">
+ <Icon name="check_filled" />
+ {t`Script executed successfully`}
</Flex>
);
}
-function ExecutionLogs({
- label,
- content,
-}: {
- label: string;
- content?: string | null;
-}) {
- if (!content) {
- return null;
- }
-
- return (
- <Section title={label}>
- <Box p="sm" bg="bg-light" mah="150px" bdrs="xs" className={S.logs}>
- {content}
- </Box>
- </Section>
- );
-}
-
-function Section({
- title,
- children,
+function ExecutionOutputLogs({
+ executionResult,
}: {
- title: ReactNode;
- children: ReactNode;
+ executionResult: TestPythonTransformResponse | null;
}) {
return (
- <Box>
- {title && (
- <Title order={5} mb="xs">
- {title}
- </Title>
+ <Box fz="sm" p="md" bg="bg-light" h="100%" className={S.logs}>
+ {executionResult?.logs ? (
+ <AnsiLogs>{executionResult.logs}</AnsiLogs>
+ ) : (
+ <Text c="text-light" fz="sm" fs="italic">{t`No logs to display`}</Text>
)}
- {children}
</Box>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
index 3ede1dde527..408b8093ebb 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonTransformEditor.tsx
@@ -4,15 +4,13 @@ import type { PythonTransformEditorProps } from "metabase/plugins";
import { Flex, Stack } from "metabase/ui";
import type { PythonTransformTableAliases, Table } from "metabase-types/api";
+import { isPythonTransformSource } from "../../utils";
+
import { PythonDataPicker } from "./PythonDataPicker";
import { PythonEditorBody } from "./PythonEditorBody";
import { PythonEditorResults } from "./PythonEditorResults";
-import {
- isPythonTransformSource,
- updateTransformSignature,
- useShouldShowPythonDebugger,
- useTestPythonTransform,
-} from "./utils";
+import { useTestPythonTransform } from "./hooks";
+import { updateTransformSignature } from "./utils";
export function PythonTransformEditor({
source,
@@ -53,12 +51,7 @@ export function PythonTransformEditor({
onChangeSource(newSource);
};
- const showDebugger = useShouldShowPythonDebugger();
-
const handleCmdEnter = () => {
- if (!showDebugger) {
- return;
- }
if (isRunning) {
cancel();
} else if (isPythonTransformSource(source)) {
@@ -85,16 +78,14 @@ export function PythonTransformEditor({
source={source.body}
proposedSource={proposedSource?.body}
onChange={handleScriptChange}
- withDebugger={showDebugger}
+ withDebugger
onAcceptProposed={onAcceptProposed}
onRejectProposed={onRejectProposed}
/>
- {showDebugger && (
- <PythonEditorResults
- isRunning={isRunning}
- executionResult={executionResult}
- />
- )}
+ <PythonEditorResults
+ isRunning={isRunning}
+ executionResult={executionResult}
+ />
</Stack>
</Flex>
);
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/hooks.ts b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/hooks.ts
new file mode 100644
index 00000000000..fc8b6ee4cb3
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/hooks.ts
@@ -0,0 +1,74 @@
+import { useRef } from "react";
+import { t } from "ttag";
+
+import { getErrorMessage } from "metabase/api/utils";
+import { useExecutePythonMutation } from "metabase-enterprise/api/transform-python";
+import type {
+ PythonTransformSourceDraft,
+ TestPythonTransformResponse,
+} from "metabase-types/api";
+
+type TestPythonScriptState = {
+ isRunning: boolean;
+ isDirty: boolean;
+ executionResult: TestPythonTransformResponse;
+ run: () => void;
+ cancel: () => void;
+};
+
+export function useTestPythonTransform(
+ source: PythonTransformSourceDraft,
+): TestPythonScriptState {
+ const [
+ executePython,
+ { data = null, error, isLoading: isRunning, originalArgs },
+ ] = useExecutePythonMutation();
+ const abort = useRef<(() => void) | null>(null);
+
+ const isDirty = originalArgs?.code !== source.body;
+
+ const run = async () => {
+ if (source["source-database"] === undefined) {
+ return null;
+ }
+
+ const request = executePython({
+ code: source.body,
+ source_tables: source["source-tables"],
+ });
+
+ abort.current = () => request.abort();
+ };
+
+ const cancel = () => {
+ abort.current?.();
+ };
+
+ const executionResult = {
+ ...data,
+ error: getError(error) ?? data?.error,
+ };
+
+ return {
+ isRunning,
+ isDirty,
+ cancel,
+ run,
+ executionResult,
+ };
+}
+
+function getError(error: unknown) {
+ if (!error) {
+ return null;
+ }
+
+ if (typeof error === "object" && error !== null) {
+ if ("name" in error && error.name === "AbortError") {
+ return { message: t`Python script execution was canceled` };
+ }
+ }
+ return {
+ message: getErrorMessage(error, t`An unknown error occurred`),
+ };
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/utils.ts b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/utils.ts
index e3945178838..96446a33de1 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/utils.ts
@@ -1,13 +1,4 @@
-import { useRef, useState } from "react";
-import { useLocation } from "react-use";
-import { t } from "ttag";
-
-import { getErrorMessage } from "metabase/api/utils";
-import { useExecutePythonMutation } from "metabase-enterprise/api/transform-python";
import type {
- ExecutePythonTransformResponse,
- PythonTransformSource,
- PythonTransformSourceDraft,
PythonTransformTableAliases,
Table,
TableId,
@@ -147,75 +138,3 @@ ${tableAliases
return script + functionTemplate;
}
-
-export type ExecutionResult = {
- output?: string;
- stdout?: string;
- stderr?: string;
- error?: string;
-};
-
-type TestPythonScriptState = {
- executionResult: ExecutionResult | null;
- isRunning: boolean;
- run: () => void;
- cancel: () => void;
-};
-
-export function useTestPythonTransform(
- source: PythonTransformSourceDraft,
-): TestPythonScriptState {
- const [executePython, { isLoading: isRunning }] = useExecutePythonMutation();
- const abort = useRef<(() => void) | null>(null);
- const [executionResult, setData] =
- useState<ExecutePythonTransformResponse | null>(null);
-
- const run = async () => {
- if (source["source-database"] === undefined) {
- return null;
- }
- const request = executePython({
- code: source.body,
- tables: source["source-tables"],
- });
- abort.current = () => request.abort();
-
- try {
- const data = await request.unwrap();
- setData(data);
- } catch (error) {
- if (typeof error === "object" && error !== null) {
- if ("name" in error && error.name === "AbortError") {
- setData({ error: t`Python script execution was canceled` });
- return;
- }
- }
-
- const errorMessage = getErrorMessage(error, t`An unknown error occurred`);
- setData({ error: errorMessage });
- }
- };
-
- const cancel = () => {
- abort.current?.();
- };
-
- return {
- executionResult,
- isRunning,
- run,
- cancel,
- };
-}
-
-export function isPythonTransformSource(
- source: PythonTransformSourceDraft,
-): source is PythonTransformSource {
- return source.type === "python" && source["source-database"] !== undefined;
-}
-
-export function useShouldShowPythonDebugger() {
- const location = useLocation();
- const params = new URLSearchParams(location.search);
- return params.get("debugger") === "1";
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/utils.ts b/enterprise/frontend/src/metabase-enterprise/transforms-python/utils.ts
index 8cba43228ed..59cacbdd91a 100644
--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/utils.ts
@@ -1,7 +1,10 @@
import { t } from "ttag";
import type { PythonTransformSourceValidationResult } from "metabase/plugins";
-import type { PythonTransformSourceDraft } from "metabase-types/api";
+import type {
+ PythonTransformSource,
+ PythonTransformSourceDraft,
+} from "metabase-types/api";
export function getPythonSourceValidationResult(
source: PythonTransformSourceDraft,
@@ -26,3 +29,9 @@ export function getPythonSourceValidationResult(
return { isValid: true };
}
+
+export function isPythonTransformSource(
+ source: PythonTransformSourceDraft,
+): source is PythonTransformSource {
+ return source.type === "python" && source["source-database"] !== undefined;
+}
diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.ts
index f406e4f94ac..21e27c69b57 100644
--- a/frontend/src/metabase-types/api/settings.ts
+++ b/frontend/src/metabase-types/api/settings.ts
@@ -710,6 +710,7 @@ export interface EnterpriseSettings extends Settings {
"python-storage-s-3-endpoint"?: string | null;
"python-storage-s-3-region"?: string | null;
"python-storage-s-3-bucket"?: string | null;
+ "python-storage-s-3-prefix"?: string | null;
"python-storage-s-3-access-key"?: string | null;
"python-storage-s-3-secret-key"?: string | null;
"python-storage-s-3-container-endpoint"?: string | null;
diff --git a/frontend/src/metabase-types/api/transform.ts b/frontend/src/metabase-types/api/transform.ts
index 7430d7fdf9b..79170d80b4b 100644
--- a/frontend/src/metabase-types/api/transform.ts
+++ b/frontend/src/metabase-types/api/transform.ts
@@ -1,4 +1,5 @@
import type { DatabaseId } from "./database";
+import type { RowValue } from "./dataset";
import type { PaginationRequest, PaginationResponse } from "./pagination";
import type { DatasetQuery } from "./query";
import type { ScheduleDisplayType } from "./settings";
@@ -215,18 +216,18 @@ export type ListTransformRunsResponse = {
data: TransformRun[];
} & PaginationResponse;
-export type ExecutePythonTransformRequest = {
+export type TestPythonTransformRequest = {
code: string;
- tables: PythonTransformTableAliases;
+ source_tables: PythonTransformTableAliases;
};
-export type ExecutePythonTransformResponse = {
- output?: string;
- stdout?: string;
- stderr?: string;
- error?: string;
- exit_code?: number;
- timeout?: boolean;
+export type TestPythonTransformResponse = {
+ logs?: string;
+ error?: { message: string };
+ output?: {
+ cols: { name: string }[];
+ rows: Record<string, RowValue>[];
+ };
};
export type PythonLibrary = {