Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(superset): Add patch that fixes saved queries export #539

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 \
sbernauer marked this conversation as resolved.
Show resolved Hide resolved
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 || {

Check notice on line 38 in superset/stackable/patches/apply_patches.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] superset/stackable/patches/apply_patches.sh#L38 <ShellCheck.SC2002>

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Raw output
./superset/stackable/patches/apply_patches.sh:38:7: info: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. (ShellCheck.SC2002)
echo "Failed to apply $patch_file"
exit 1
}
done

echo "All patches applied successfully."