Skip to content

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

ensure common.py library is always available (#68603)

Nicola Mometto094109142109
diff --git a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
index 07d08a168e6..1764e8cd176 100644
--- a/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/transforms.cy.spec.ts
@@ -2319,6 +2319,62 @@ LIMIT
},
);
+ it(
+ "should be able to run a transform with default import common even without custom library code",
+ { tags: ["@python"] },
+ () => {
+ setPythonRunnerSettings();
+
+ visitTransformListPage();
+ cy.button("Create a transform").click();
+ H.popover().findByText("Python script").click();
+
+ cy.log("import common should be included by default");
+ H.PythonEditor.value().should("contain", "import common");
+
+ cy.log(
+ "write a transform that imports common but does not use it - should still run",
+ );
+ H.PythonEditor.clear().type(
+ dedent`
+ import common
+ import pandas as pd
+
+ def transform():
+ return pd.DataFrame([{"result": 42}])
+ `,
+ { allowFastSet: true },
+ );
+
+ cy.findByTestId("python-data-picker")
+ .findByText("Select a table…")
+ .click();
+
+ H.entityPickerModal().within(() => {
+ cy.findByText("Schema a").click();
+ cy.findByText("Animals").click();
+ });
+
+ getQueryEditor().button("Save").click();
+
+ H.modal().within(() => {
+ cy.findByLabelText("Name").clear().type("Default common transform");
+ cy.findByLabelText("Table name").clear().type("default_common");
+ cy.button("Save").click();
+ });
+
+ H.DataStudio.Transforms.runTab().click();
+ runTransformAndWaitForSuccess();
+ H.DataStudio.Transforms.settingsTab().click();
+ getTableLink().click();
+ H.queryBuilderHeader()
+ .findByText("Default Common")
+ .should("be.visible");
+ H.assertQueryBuilderRowCount(1);
+ cy.findByTestId("scalar-value").should("have.text", "42");
+ },
+ );
+
function visitCommonLibrary(path = "common.py") {
cy.visit(`/data-studio/transforms/library/${path}`);
}
diff --git a/resources/migrations/059_update_migrations.yaml b/resources/migrations/059_update_migrations.yaml
index 3e974cf741d..f5deb014722 100644
--- a/resources/migrations/059_update_migrations.yaml
+++ b/resources/migrations/059_update_migrations.yaml
@@ -730,6 +730,20 @@ databaseChangeLog:
path: instance_analytics_views/tasks/v2/h2-tasks.sql
relativeToChangelogFile: true
+ - changeSet:
+ id: v59.2026-01-23T12:00:00
+ author: bronsa
+ comment: Insert default common.py entry in python_library if not exists
+ preConditions:
+ - onFail: MARK_RAN
+ - sqlCheck:
+ expectedResult: 0
+ sql: SELECT count(*) FROM python_library WHERE path = 'common.py'
+ changes:
+ - sql:
+ sql: INSERT INTO python_library (path, source) VALUES ('common.py', '')
+ rollback:
+
# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<
########################################################################################################################