From 30f1050afb83c70b82ea3efc0cafee5fc3bb65ad Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 30 Jan 2024 17:34:55 +0100 Subject: [PATCH 1/5] feat(superset): Add patch that fixes saved queries export --- CHANGELOG.md | 1 + superset/Dockerfile | 4 ++ .../3.0.1/001-26885-query-export-fix.patch | 24 ++++++++++ superset/stackable/patches/apply_patches.sh | 44 +++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 superset/stackable/patches/3.0.1/001-26885-query-export-fix.patch create mode 100755 superset/stackable/patches/apply_patches.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 72dc86326..f988c5832 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file. - Bump ubi8-rust-builder toolchain to `1.74.0` ([#517]). - GH workflows: make preflight an independent manual workflow and update to version 1.7.2 ([#519]). - hadoop: Build from source ([#526]). +- superset: Add patch that fixes saved queries export ([#XXX]). [#493]: https://github.com/stackabletech/docker-images/pull/493 [#506]: https://github.com/stackabletech/docker-images/pull/506 diff --git a/superset/Dockerfile b/superset/Dockerfile index f82741290..9326eb3e8 100644 --- a/superset/Dockerfile +++ b/superset/Dockerfile @@ -17,6 +17,7 @@ RUN microdnf update \ && microdnf install \ --assumeyes \ cyrus-sasl-devel \ + findutils \ gcc \ gcc-c++ \ libffi-devel \ @@ -57,6 +58,9 @@ RUN microdnf update \ python-json-logger \ && if [ ! -z "$AUTHLIB" ]; then pip install Authlib==${AUTHLIB}; fi +COPY superset/stackable/patches /patches +RUN /patches/apply_patches.sh ${PRODUCT} + # Final image FROM stackable/image/vector diff --git a/superset/stackable/patches/3.0.1/001-26885-query-export-fix.patch b/superset/stackable/patches/3.0.1/001-26885-query-export-fix.patch new file mode 100644 index 000000000..765cb98d5 --- /dev/null +++ b/superset/stackable/patches/3.0.1/001-26885-query-export-fix.patch @@ -0,0 +1,24 @@ +diff --git a/superset/queries/saved_queries/commands/export.py b/superset/queries/saved_queries/commands/export.py +index a8fa8acbf..074a4ace2 100644 +--- a/superset/queries/saved_queries/commands/export.py ++++ b/superset/queries/saved_queries/commands/export.py +@@ -40,11 +40,16 @@ class ExportSavedQueriesCommand(ExportModelsCommand): + def _export( + model: SavedQuery, export_related: bool = True + ) -> Iterator[tuple[str, str]]: +- # build filename based on database, optional schema, and label ++ # build filename based on database, optional schema, and label. ++ # we call secure_filename() multiple times and join the directories afterwards, ++ # as secure_filename() replaces "/" with "_". + database_slug = secure_filename(model.database.database_name) +- schema_slug = secure_filename(model.schema) + query_slug = secure_filename(model.label) or str(model.uuid) +- file_name = f"queries/{database_slug}/{schema_slug}/{query_slug}.yaml" ++ if model.schema is None: ++ file_name = f"queries/{database_slug}/{query_slug}.yaml" ++ else: ++ schema_slug = secure_filename(model.schema) ++ file_name = f"queries/{database_slug}/{schema_slug}/{query_slug}.yaml" + + payload = model.export_to_dict( + recursive=False, diff --git a/superset/stackable/patches/apply_patches.sh b/superset/stackable/patches/apply_patches.sh new file mode 100755 index 000000000..5d5b39ff3 --- /dev/null +++ b/superset/stackable/patches/apply_patches.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Enable error handling and unset variable checking +set -eu +set -o pipefail + +# Check if $1 (VERSION) is provided +if [ -z "${1-}" ]; then + echo "Please provide a value for VERSION as the first argument." + exit 1 +fi + +VERSION="$1" +PATCH_DIR="patches/$VERSION" + +# Check if version-specific patches directory exists +if [ ! -d "$PATCH_DIR" ]; then + echo "Patches directory '$PATCH_DIR' does not exist." + exit 1 +fi + +# Create an array to hold the patches in sorted order +declare -a patch_files=() + +echo "Applying patches from ${PATCH_DIR}" now + +# Read the patch files into the array +while IFS= read -r -d $'\0' file; do + patch_files+=("$file") +done < <(find "$PATCH_DIR" -name "*.patch" -print0 | sort -zV) + +echo "Found ${#patch_files[@]} patches, applying now" + +# Iterate through sorted patch files +for patch_file in "${patch_files[@]}"; do + echo "Applying $patch_file" + # We can not use Git here, as we are not within a Git repo + cat "$patch_file" | patch --directory "/stackable/app/lib/python${PYTHON}/site-packages" --strip=1 || { + echo "Failed to apply $patch_file" + exit 1 + } +done + +echo "All patches applied successfully." From a94b2bac68e6b38b7caaad6c33d173064c1c030b Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Tue, 30 Jan 2024 17:45:32 +0100 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f988c5832..59eed7bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ All notable changes to this project will be documented in this file. - Bump ubi8-rust-builder toolchain to `1.74.0` ([#517]). - GH workflows: make preflight an independent manual workflow and update to version 1.7.2 ([#519]). - hadoop: Build from source ([#526]). -- superset: Add patch that fixes saved queries export ([#XXX]). +- superset: Add patch that fixes saved queries export ([#539]). [#493]: https://github.com/stackabletech/docker-images/pull/493 [#506]: https://github.com/stackabletech/docker-images/pull/506 @@ -34,6 +34,7 @@ All notable changes to this project will be documented in this file. [#536]: https://github.com/stackabletech/docker-images/pull/536 [#537]: https://github.com/stackabletech/docker-images/pull/537 [#538]: https://github.com/stackabletech/docker-images/pull/538 +[#539]: https://github.com/stackabletech/docker-images/pull/539 ## [23.11.0] - 2023-11-30 From 192d6202aebcf37240c502d08d997919a65e8ef5 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 2 Feb 2024 15:24:41 +0100 Subject: [PATCH 3/5] Add empty folder for 2.1.0 and 2.1.1 --- superset/stackable/patches/2.1.0/.gitignore | 0 superset/stackable/patches/2.1.1/.gitignore | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 superset/stackable/patches/2.1.0/.gitignore create mode 100644 superset/stackable/patches/2.1.1/.gitignore diff --git a/superset/stackable/patches/2.1.0/.gitignore b/superset/stackable/patches/2.1.0/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/superset/stackable/patches/2.1.1/.gitignore b/superset/stackable/patches/2.1.1/.gitignore new file mode 100644 index 000000000..e69de29bb From 9a77be148378ff3f40f26a8d1bebb9f4fc733598 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Fri, 2 Feb 2024 15:25:59 +0100 Subject: [PATCH 4/5] Add findutils explanation --- superset/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/superset/Dockerfile b/superset/Dockerfile index 9326eb3e8..acf33a820 100644 --- a/superset/Dockerfile +++ b/superset/Dockerfile @@ -17,6 +17,7 @@ RUN microdnf update \ && microdnf install \ --assumeyes \ cyrus-sasl-devel \ + # Needed to find all patch files findutils \ gcc \ gcc-c++ \ From d58a75970581a5b85eeaf86535661a1695642029 Mon Sep 17 00:00:00 2001 From: Sebastian Bernauer Date: Mon, 5 Feb 2024 09:21:29 +0100 Subject: [PATCH 5/5] Update superset/Dockerfile Co-authored-by: Lars Francke --- superset/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/Dockerfile b/superset/Dockerfile index acf33a820..40740e5e1 100644 --- a/superset/Dockerfile +++ b/superset/Dockerfile @@ -17,7 +17,7 @@ RUN microdnf update \ && microdnf install \ --assumeyes \ cyrus-sasl-devel \ - # Needed to find all patch files + # Needed to find all patch files, used in `apply_patches.sh` findutils \ gcc \ gcc-c++ \