Skip to content

Commit

Permalink
feat(superset): Add patch that fixes saved queries export (#539)
Browse files Browse the repository at this point in the history
* feat(superset): Add patch that fixes saved queries export

* changelog

* Add empty folder for 2.1.0 and 2.1.1

* Add findutils explanation

* Update superset/Dockerfile

Co-authored-by: Lars Francke <lars.francke@stackable.tech>

---------

Co-authored-by: Lars Francke <lars.francke@stackable.tech>
  • Loading branch information
sbernauer and lfrancke authored Feb 5, 2024
1 parent 7cf9314 commit 85c2740
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
- ubi8-rust-builder: bump rust toolchain to `1.75.0` ([#542], [#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 ([#539]).

[#493]: https://github.com/stackabletech/docker-images/pull/493
[#506]: https://github.com/stackabletech/docker-images/pull/506
Expand All @@ -33,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
[#542]: https://github.com/stackabletech/docker-images/pull/542

## [23.11.0] - 2023-11-30
Expand Down
5 changes: 5 additions & 0 deletions superset/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ RUN microdnf update \
&& microdnf install \
--assumeyes \
cyrus-sasl-devel \
# Needed to find all patch files, used in `apply_patches.sh`
findutils \
gcc \
gcc-c++ \
libffi-devel \
Expand Down Expand Up @@ -57,6 +59,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

Expand Down
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions superset/stackable/patches/3.0.1/001-26885-query-export-fix.patch
Original file line number Diff line number Diff line change
@@ -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,
44 changes: 44 additions & 0 deletions superset/stackable/patches/apply_patches.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 85c2740

Please sign in to comment.