mirror of
https://github.com/apache/superset.git
synced 2026-08-14 03:51:21 +00:00
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29fd4a3094 | ||
|
|
cd6cc34735 | ||
|
|
04077ce934 | ||
|
|
092faa019b | ||
|
|
1f17b975d6 | ||
|
|
15ede02c25 | ||
|
|
4bccf36375 | ||
|
|
21e794a66f | ||
|
|
e1f98e246f | ||
|
|
bf56a327f4 | ||
|
|
cd200f07a5 | ||
|
|
4ff9aac1fa | ||
|
|
988da2c477 | ||
|
|
f510f42b96 | ||
|
|
43314dc8db | ||
|
|
423a0fefa5 | ||
|
|
fd57fce977 | ||
|
|
d8fbaa4cbe |
@@ -45,3 +45,4 @@ superset-frontend/coverage/
|
||||
superset/static/assets/
|
||||
superset-websocket/dist/
|
||||
venv
|
||||
.venv
|
||||
|
||||
@@ -148,14 +148,26 @@ jobs:
|
||||
- name: Setup supersetbot
|
||||
uses: ./.github/actions/setup-supersetbot/
|
||||
|
||||
- name: Try to login to DockerHub
|
||||
if: steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker
|
||||
continue-on-error: true
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build ephemeral env image
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
run: |
|
||||
supersetbot docker \
|
||||
--preset ci \
|
||||
--platform linux/amd64 \
|
||||
--context-ref "$RELEASE"
|
||||
--context-ref "$RELEASE" \
|
||||
--extra-flags "--build-arg INCLUDE_CHROMIUM=false"
|
||||
|
||||
- name: Configure AWS credentials
|
||||
uses: aws-actions/configure-aws-credentials@v4
|
||||
|
||||
@@ -81,17 +81,3 @@ repos:
|
||||
- id: ruff
|
||||
args: [ --fix ]
|
||||
- id: ruff-format
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint
|
||||
name: pylint
|
||||
entry: pylint
|
||||
language: system
|
||||
types: [python]
|
||||
exclude: ^(tests/|superset/migrations/|scripts/|RELEASING/|docker/)
|
||||
args:
|
||||
[
|
||||
"-rn", # Only display messages
|
||||
"-sn", # Don't display the score
|
||||
"--rcfile=.pylintrc",
|
||||
]
|
||||
|
||||
@@ -1,380 +0,0 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
[MASTER]
|
||||
|
||||
# Specify a configuration file.
|
||||
#rcfile=
|
||||
|
||||
# Python code to execute, usually for sys.path manipulation such as
|
||||
# pygtk.require().
|
||||
#init-hook=
|
||||
|
||||
# Add files or directories to the blacklist. They should be base names, not
|
||||
# paths.
|
||||
ignore=CVS,migrations
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=
|
||||
|
||||
# Pickle collected data for later comparisons.
|
||||
persistent=yes
|
||||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
# usually to register additional checkers.
|
||||
load-plugins=superset.extensions.pylint
|
||||
|
||||
# Use multiple processes to speed up Pylint.
|
||||
jobs=2
|
||||
|
||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
||||
# active Python interpreter and may run arbitrary code.
|
||||
unsafe-load-any-extension=no
|
||||
|
||||
# A comma-separated list of package or module names from where C extensions may
|
||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
||||
# run arbitrary code
|
||||
extension-pkg-whitelist=pyarrow
|
||||
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
|
||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
||||
confidence=
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
# multiple time (only on the command line, not in the configuration file where
|
||||
# it should appear only once). See also the "--disable" option for examples.
|
||||
enable=
|
||||
useless-suppression,
|
||||
|
||||
# Disable the message, report, category or checker with the given id(s). You
|
||||
# can either give multiple identifiers separated by comma (,) or put this
|
||||
# option multiple times (only on the command line, not in the configuration
|
||||
# file where it should appear only once).You can also use "--disable=all" to
|
||||
# disable everything first and then reenable specific checks. For example, if
|
||||
# you want to run only the similarities checker, you can use "--disable=all
|
||||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
disable=
|
||||
cyclic-import, # re-enable once this no longer raises false positives
|
||||
missing-docstring,
|
||||
duplicate-code,
|
||||
line-too-long,
|
||||
unspecified-encoding,
|
||||
too-many-instance-attributes # re-enable once this no longer raises false positives
|
||||
|
||||
[REPORTS]
|
||||
|
||||
# Set the output format. Available formats are text, parseable, colorized, msvs
|
||||
# (visual studio) and html. You can also give a reporter class, eg
|
||||
# mypackage.mymodule.MyReporterClass.
|
||||
output-format=text
|
||||
|
||||
# Tells whether to display a full report or only the messages
|
||||
reports=yes
|
||||
|
||||
# Python expression which should return a note less than 10 (10 is the highest
|
||||
# note). You have access to the variables errors warning, statement which
|
||||
# respectively contain the number of errors / warnings messages and the total
|
||||
# number of statements analyzed. This is used by the global evaluation report
|
||||
# (RP0004).
|
||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
||||
|
||||
# Template used to display messages. This is a python new-style format string
|
||||
# used to format the message information. See doc for all details
|
||||
#msg-template=
|
||||
|
||||
|
||||
[BASIC]
|
||||
|
||||
# Good variable names which should always be accepted, separated by a comma
|
||||
good-names=_,df,ex,f,i,id,j,k,l,o,pk,Run,ts,v,x,y
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=bar,baz,db,fd,foo,sesh,session,tata,toto,tutu
|
||||
|
||||
# Colon-delimited sets of names that determine each other's naming style when
|
||||
# the name regexes allow several styles.
|
||||
name-group=
|
||||
|
||||
# Include a hint for the correct naming format with invalid-name
|
||||
include-naming-hint=no
|
||||
|
||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
||||
# to this list to register other decorators that produce valid properties.
|
||||
property-classes=
|
||||
abc.abstractproperty,
|
||||
sqlalchemy.ext.hybrid.hybrid_property
|
||||
|
||||
# Regular expression matching correct argument names
|
||||
argument-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct method names
|
||||
method-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct variable names
|
||||
variable-rgx=[a-z_][a-z0-9_]{1,30}$
|
||||
|
||||
# Regular expression matching correct inline iteration names
|
||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Regular expression matching correct constant names
|
||||
const-rgx=(([A-Za-z_][A-Za-z0-9_]*)|(__.*__))$
|
||||
|
||||
# Regular expression matching correct class names
|
||||
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
|
||||
# Regular expression matching correct class attribute names
|
||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Regular expression matching correct module names
|
||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Regular expression matching correct attribute names
|
||||
attr-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct function names
|
||||
function-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression which should only match function or class names that do
|
||||
# not require a docstring.
|
||||
no-docstring-rgx=^_
|
||||
|
||||
# Minimum line length for functions/classes that require docstrings, shorter
|
||||
# ones are exempt.
|
||||
docstring-min-length=10
|
||||
|
||||
|
||||
[ELIF]
|
||||
|
||||
# Maximum number of nested blocks for function / method body
|
||||
max-nested-blocks=5
|
||||
|
||||
|
||||
[FORMAT]
|
||||
|
||||
# Maximum number of characters on a single line.
|
||||
max-line-length=100
|
||||
|
||||
# Regexp for a line that is allowed to be longer than the limit.
|
||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||
|
||||
# Allow the body of an if to be on the same line as the test if there is no
|
||||
# else.
|
||||
single-line-if-stmt=no
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1000
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
indent-string=' '
|
||||
|
||||
# Number of spaces of indent required inside a hanging or continued line.
|
||||
indent-after-paren=4
|
||||
|
||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||
expected-line-ending-format=
|
||||
|
||||
|
||||
[LOGGING]
|
||||
|
||||
# Logging modules to check that the string format arguments are in logging
|
||||
# function parameter format
|
||||
logging-modules=logging
|
||||
|
||||
|
||||
[MISCELLANEOUS]
|
||||
|
||||
# List of note tags to take in consideration, separated by a comma.
|
||||
notes=FIXME,XXX
|
||||
|
||||
|
||||
[SIMILARITIES]
|
||||
|
||||
# Minimum lines number of a similarity.
|
||||
min-similarity-lines=5
|
||||
|
||||
# Ignore comments when computing similarities.
|
||||
ignore-comments=yes
|
||||
|
||||
# Ignore docstrings when computing similarities.
|
||||
ignore-docstrings=yes
|
||||
|
||||
# Ignore imports when computing similarities.
|
||||
ignore-imports=no
|
||||
|
||||
|
||||
[SPELLING]
|
||||
|
||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
||||
# install python-enchant package.
|
||||
spelling-dict=
|
||||
|
||||
# List of comma separated words that should not be checked.
|
||||
spelling-ignore-words=
|
||||
|
||||
# A path to a file that contains private dictionary; one word per line.
|
||||
spelling-private-dict-file=
|
||||
|
||||
# Tells whether to store unknown words to indicated private dictionary in
|
||||
# --spelling-private-dict-file option instead of raising a message.
|
||||
spelling-store-unknown-words=no
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||
ignore-mixin-members=yes
|
||||
|
||||
# List of module names for which member attributes should not be checked
|
||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||
# supports qualified module names, as well as Unix pattern matching.
|
||||
ignored-modules=numpy,pandas,alembic.op,sqlalchemy,alembic.context,flask_appbuilder.security.sqla.PermissionView.role,flask_appbuilder.Model.metadata,flask_appbuilder.Base.metadata
|
||||
|
||||
# List of class names for which member attributes should not be checked (useful
|
||||
# for classes with dynamically set attributes). This supports the use of
|
||||
# qualified names.
|
||||
ignored-classes=contextlib.closing,optparse.Values,thread._local,_thread._local
|
||||
|
||||
# List of members which are set dynamically and missed by pylint inference
|
||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||
# expressions are accepted.
|
||||
generated-members=
|
||||
|
||||
# List of decorators that produce context managers, such as
|
||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
||||
# produce valid context managers.
|
||||
contextmanager-decorators=contextlib.contextmanager
|
||||
|
||||
|
||||
[VARIABLES]
|
||||
|
||||
# Tells whether we should check for unused import in __init__ files.
|
||||
init-import=no
|
||||
|
||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
||||
# not used).
|
||||
dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy
|
||||
|
||||
# List of additional names supposed to be defined in builtins. Remember that
|
||||
# you should avoid to define new builtins when possible.
|
||||
additional-builtins=
|
||||
|
||||
# List of strings which can identify a callback function by name. A callback
|
||||
# name must start or end with one of those strings.
|
||||
callbacks=cb_,_cb
|
||||
|
||||
# List of qualified module names which can have objects that can redefine
|
||||
# builtins.
|
||||
redefining-builtins-modules=six.moves,future.builtins
|
||||
|
||||
|
||||
[CLASSES]
|
||||
|
||||
# List of method names used to declare (i.e. assign) instance attributes.
|
||||
defining-attr-methods=__init__,__new__,setUp
|
||||
|
||||
# List of valid names for the first argument in a class method.
|
||||
valid-classmethod-first-arg=cls
|
||||
|
||||
# List of valid names for the first argument in a metaclass class method.
|
||||
valid-metaclass-classmethod-first-arg=mcs
|
||||
|
||||
# List of member names, which should be excluded from the protected access
|
||||
# warning.
|
||||
exclude-protected=_asdict,_fields,_replace,_source,_make
|
||||
|
||||
|
||||
[DESIGN]
|
||||
|
||||
# Maximum number of arguments for function / method
|
||||
max-args=5
|
||||
|
||||
# Argument names that match this expression will be ignored. Default to name
|
||||
# with leading underscore
|
||||
ignored-argument-names=_.*
|
||||
|
||||
# Maximum number of locals for function / method body
|
||||
max-locals=15
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=10
|
||||
|
||||
# Maximum number of branch for function / method body
|
||||
max-branches=15
|
||||
|
||||
# Maximum number of statements in function / method body
|
||||
max-statements=50
|
||||
|
||||
# Maximum number of parents for a class (see R0901).
|
||||
max-parents=7
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
max-attributes=8
|
||||
|
||||
# Minimum number of public methods for a class (see R0903).
|
||||
min-public-methods=2
|
||||
|
||||
# Maximum number of public methods for a class (see R0904).
|
||||
max-public-methods=20
|
||||
|
||||
# Maximum number of boolean expressions in a if statement
|
||||
max-bool-expr=5
|
||||
|
||||
|
||||
[IMPORTS]
|
||||
|
||||
# Deprecated modules which should not be used, separated by a comma
|
||||
deprecated-modules=optparse
|
||||
|
||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
||||
# given file (report RP0402 must not be disabled)
|
||||
import-graph=
|
||||
|
||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
ext-import-graph=
|
||||
|
||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
int-import-graph=
|
||||
|
||||
# Force import order to recognize a module as part of the standard
|
||||
# compatibility libraries.
|
||||
known-standard-library=
|
||||
|
||||
# Force import order to recognize a module as part of a third party library.
|
||||
known-third-party=enchant
|
||||
|
||||
# Analyse import fallback blocks. This can be used to support both Python 2 and
|
||||
# 3 compatible code, which means that the block might have code that exists
|
||||
# only in one or another interpreter, leading to false positives when analysed.
|
||||
analyse-fallback-blocks=no
|
||||
|
||||
|
||||
[EXCEPTIONS]
|
||||
|
||||
# Exceptions that will emit a warning when being caught. Defaults to
|
||||
# "Exception"
|
||||
overgeneral-exceptions=builtins.Exception
|
||||
+132
-139
@@ -22,26 +22,29 @@ ARG PY_VER=3.10-slim-bookworm
|
||||
|
||||
# If BUILDPLATFORM is null, set it to 'amd64' (or leave as is otherwise).
|
||||
ARG BUILDPLATFORM=${BUILDPLATFORM:-amd64}
|
||||
FROM --platform=${BUILDPLATFORM} node:20-bullseye-slim AS superset-node
|
||||
|
||||
######################################################################
|
||||
# superset-node used for building frontend assets
|
||||
######################################################################
|
||||
FROM --platform=${BUILDPLATFORM} node:20-bullseye-slim AS superset-node
|
||||
ARG BUILD_TRANSLATIONS="false" # Include translations in the final build
|
||||
ENV BUILD_TRANSLATIONS=${BUILD_TRANSLATIONS}
|
||||
ARG DEV_MODE="false" # Skip frontend build in dev mode
|
||||
ENV DEV_MODE=${DEV_MODE}
|
||||
|
||||
COPY docker/ /app/docker/
|
||||
# Arguments for build configuration
|
||||
ARG NPM_BUILD_CMD="build"
|
||||
ARG BUILD_TRANSLATIONS="false" # Include translations in the final build
|
||||
ARG DEV_MODE="false" # Skip frontend build in dev mode
|
||||
ARG INCLUDE_CHROMIUM="true" # Include headless Chromium for alerts & reports
|
||||
ARG INCLUDE_FIREFOX="false" # Include headless Firefox if enabled
|
||||
|
||||
# Install system dependencies required for node-gyp
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
/docker/apt-install.sh build-essential python3 zstd
|
||||
RUN /app/docker/apt-install.sh build-essential python3 zstd
|
||||
|
||||
# Define environment variables for frontend build
|
||||
ENV BUILD_CMD=${NPM_BUILD_CMD} \
|
||||
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
|
||||
|
||||
# Run the frontend memory monitoring script
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
/docker/frontend-mem-nag.sh
|
||||
RUN /app/docker/frontend-mem-nag.sh
|
||||
|
||||
WORKDIR /app/superset-frontend
|
||||
|
||||
@@ -49,6 +52,9 @@ WORKDIR /app/superset-frontend
|
||||
RUN mkdir -p /app/superset/static/assets \
|
||||
/app/superset/translations
|
||||
|
||||
# Copy translation files
|
||||
COPY superset/translations /app/superset/translations
|
||||
|
||||
# Mount package files and install dependencies if not in dev mode
|
||||
RUN --mount=type=bind,source=./superset-frontend/package.json,target=./package.json \
|
||||
--mount=type=bind,source=./superset-frontend/package-lock.json,target=./package-lock.json \
|
||||
@@ -61,41 +67,28 @@ RUN --mount=type=bind,source=./superset-frontend/package.json,target=./package.j
|
||||
# Runs the webpack build process
|
||||
COPY superset-frontend /app/superset-frontend
|
||||
|
||||
|
||||
# Copy translation files
|
||||
COPY superset/translations /app/superset/translations
|
||||
|
||||
# Build the frontend if not in dev mode
|
||||
RUN if [ "$DEV_MODE" = "false" ]; then \
|
||||
BUILD_TRANSLATIONS=$BUILD_TRANSLATIONS npm run ${BUILD_CMD}; \
|
||||
echo "Running 'npm run ${BUILD_CMD}'"; \
|
||||
if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
|
||||
npm run build-translation; \
|
||||
fi; \
|
||||
npm run ${BUILD_CMD}; \
|
||||
else \
|
||||
echo "Skipping 'npm run ${BUILD_CMD}' in dev mode"; \
|
||||
fi
|
||||
|
||||
# Compile .json files from .po translations (if required) and clean up .po files
|
||||
RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
|
||||
npm run build-translation; \
|
||||
else \
|
||||
echo "Skipping translations as requested by build flag"; \
|
||||
fi \
|
||||
# removing translations files regardless
|
||||
&& rm -rf /app/superset/translations/*/LC_MESSAGES/*.po \
|
||||
/app/superset/translations/messages.pot
|
||||
fi && \
|
||||
rm -rf /app/superset/translations/*/*/*.po
|
||||
|
||||
|
||||
# Transition to Python base image
|
||||
######################################################################
|
||||
# Base python layer
|
||||
######################################################################
|
||||
FROM python:${PY_VER} AS python-base
|
||||
RUN pip install --no-cache-dir --upgrade setuptools pip uv
|
||||
ARG BUILD_TRANSLATIONS="false" # Include translations in the final build
|
||||
ENV BUILD_TRANSLATIONS=${BUILD_TRANSLATIONS}
|
||||
ARG DEV_MODE="false" # Skip frontend build in dev mode
|
||||
ENV DEV_MODE=${DEV_MODE}
|
||||
|
||||
######################################################################
|
||||
# Final lean image...
|
||||
######################################################################
|
||||
FROM python-base AS lean
|
||||
|
||||
# Build argument for including translations
|
||||
ARG BUILD_TRANSLATIONS="false"
|
||||
|
||||
WORKDIR /app
|
||||
ENV LANG=C.UTF-8 \
|
||||
LC_ALL=C.UTF-8 \
|
||||
SUPERSET_ENV=production \
|
||||
@@ -104,126 +97,128 @@ ENV LANG=C.UTF-8 \
|
||||
SUPERSET_HOME="/app/superset_home" \
|
||||
SUPERSET_PORT=8088
|
||||
|
||||
|
||||
RUN useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset
|
||||
|
||||
# Some bash scripts needed throughout the layers
|
||||
COPY --chmod=755 docker/*.sh /app/docker/
|
||||
|
||||
RUN pip install --no-cache-dir --upgrade setuptools pip uv
|
||||
|
||||
# Using uv as it's faster/simpler than pip
|
||||
RUN uv venv /app/.venv
|
||||
ENV PATH="/app/.venv/bin:${PATH}"
|
||||
|
||||
# Install Playwright and optionally setup headless browsers
|
||||
ARG INCLUDE_CHROMIUM="true"
|
||||
ARG INCLUDE_FIREFOX="false"
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
if [ "$INCLUDE_CHROMIUM" = "true" ] || [ "$INCLUDE_FIREFOX" = "true" ]; then \
|
||||
pip install playwright && \
|
||||
playwright install-deps && \
|
||||
if [ "$INCLUDE_CHROMIUM" = "true" ]; then playwright install chromium; fi && \
|
||||
if [ "$INCLUDE_FIREFOX" = "true" ]; then playwright install firefox; fi; \
|
||||
else \
|
||||
echo "Skipping browser installation"; \
|
||||
fi
|
||||
|
||||
######################################################################
|
||||
# Python translation compiler layer
|
||||
######################################################################
|
||||
FROM python-base AS python-translation-compiler
|
||||
|
||||
# Install Python dependencies using docker/pip-install.sh
|
||||
COPY requirements/translations.txt requirements/
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
/app/docker/pip-install.sh -r requirements/translations.txt
|
||||
|
||||
COPY superset/translations/ /app/translations_mo/
|
||||
RUN pybabel compile -d /app/translations_mo | true && \
|
||||
rm -f /app/translations_mo/*/*/*.po
|
||||
|
||||
######################################################################
|
||||
# Python APP common layer
|
||||
######################################################################
|
||||
FROM python-base AS python-common
|
||||
# Copy the entrypoints, make them executable in userspace
|
||||
COPY --chmod=755 docker/entrypoints /app/docker/entrypoints
|
||||
|
||||
WORKDIR /app
|
||||
# Set up necessary directories and user
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
mkdir -p ${PYTHONPATH} \
|
||||
RUN mkdir -p \
|
||||
${SUPERSET_HOME} \
|
||||
${PYTHONPATH} \
|
||||
superset/static \
|
||||
requirements \
|
||||
superset-frontend \
|
||||
apache_superset.egg-info \
|
||||
requirements \
|
||||
&& useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \
|
||||
&& /docker/apt-install.sh \
|
||||
curl \
|
||||
libsasl2-dev \
|
||||
libsasl2-modules-gssapi-mit \
|
||||
libpq-dev \
|
||||
libecpg-dev \
|
||||
libldap2-dev \
|
||||
&& touch superset/static/version_info.json \
|
||||
&& chown -R superset:superset ./* \
|
||||
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
|
||||
&& touch superset/static/version_info.json
|
||||
|
||||
# Copy required files for Python build
|
||||
COPY --chown=superset:superset pyproject.toml setup.py MANIFEST.in README.md ./
|
||||
COPY --chown=superset:superset superset-frontend/package.json superset-frontend/
|
||||
COPY --chown=superset:superset requirements/base.txt requirements/
|
||||
COPY --chown=superset:superset scripts/check-env.py scripts/
|
||||
COPY pyproject.toml setup.py MANIFEST.in README.md ./
|
||||
COPY superset-frontend/package.json superset-frontend/
|
||||
COPY scripts/check-env.py scripts/
|
||||
|
||||
# keeping for backward compatibility
|
||||
COPY --chmod=755 ./docker/entrypoints/run-server.sh /usr/bin/
|
||||
|
||||
# Some debian libs
|
||||
RUN /app/docker/apt-install.sh \
|
||||
curl \
|
||||
libsasl2-dev \
|
||||
libsasl2-modules-gssapi-mit \
|
||||
libpq-dev \
|
||||
libecpg-dev \
|
||||
libldap2-dev
|
||||
|
||||
# Copy compiled things from previous stages
|
||||
COPY --from=superset-node /app/superset/static/assets superset/static/assets
|
||||
|
||||
# Merging translations from backend and frontend stages
|
||||
COPY --from=superset-node /app/superset/translations superset/translations
|
||||
COPY --from=python-translation-compiler /app/translations_mo superset/translations
|
||||
|
||||
HEALTHCHECK CMD curl -f "http://localhost:${SUPERSET_PORT}/health"
|
||||
CMD ["/app/docker/entrypoints/run-server.sh"]
|
||||
EXPOSE ${SUPERSET_PORT}
|
||||
|
||||
######################################################################
|
||||
# Final lean image...
|
||||
######################################################################
|
||||
FROM python-common AS lean
|
||||
COPY superset superset
|
||||
|
||||
# Install Python dependencies using docker/pip-install.sh
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
--mount=type=cache,target=/root/.cache/pip \
|
||||
/docker/pip-install.sh --requires-build-essential -r requirements/base.txt
|
||||
COPY requirements/base.txt requirements/
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
/app/docker/pip-install.sh --requires-build-essential -r requirements/base.txt && \
|
||||
uv pip install .
|
||||
|
||||
# Copy the compiled frontend assets from the node image
|
||||
COPY --chown=superset:superset --from=superset-node /app/superset/static/assets superset/static/assets
|
||||
RUN python -m compileall /app/superset
|
||||
|
||||
# Copy the main Superset source code
|
||||
COPY --chown=superset:superset superset superset
|
||||
|
||||
# Install Superset itself using docker/pip-install.sh
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
--mount=type=cache,target=/root/.cache/pip \
|
||||
/docker/pip-install.sh -e .
|
||||
|
||||
# Copy .json translations from the node image
|
||||
COPY --chown=superset:superset --from=superset-node /app/superset/translations superset/translations
|
||||
|
||||
# Compile backend translations and clean up
|
||||
COPY ./scripts/translations/generate_mo_files.sh ./scripts/translations/
|
||||
RUN if [ "$BUILD_TRANSLATIONS" = "true" ]; then \
|
||||
./scripts/translations/generate_mo_files.sh \
|
||||
&& chown -R superset:superset superset/translations; \
|
||||
fi \
|
||||
&& rm -rf superset/translations/messages.pot \
|
||||
superset/translations/*/LC_MESSAGES/*.po
|
||||
|
||||
# Add server run script
|
||||
COPY --chmod=755 ./docker/run-server.sh /usr/bin/
|
||||
|
||||
# Set user and healthcheck
|
||||
USER superset
|
||||
HEALTHCHECK CMD curl -f "http://localhost:${SUPERSET_PORT}/health"
|
||||
|
||||
# Expose port and set CMD
|
||||
EXPOSE ${SUPERSET_PORT}
|
||||
CMD ["/usr/bin/run-server.sh"]
|
||||
|
||||
|
||||
######################################################################
|
||||
# Dev image...
|
||||
######################################################################
|
||||
FROM lean AS dev
|
||||
FROM python-common AS dev
|
||||
COPY superset superset
|
||||
|
||||
USER root
|
||||
|
||||
# Install dev dependencies
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
/docker/apt-install.sh \
|
||||
libnss3 \
|
||||
libdbus-glib-1-2 \
|
||||
libgtk-3-0 \
|
||||
libx11-xcb1 \
|
||||
libasound2 \
|
||||
libxtst6 \
|
||||
git \
|
||||
pkg-config
|
||||
|
||||
# Install Playwright and its dependencies
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
uv pip install --system playwright \
|
||||
&& playwright install-deps
|
||||
|
||||
# Optionally install Chromium
|
||||
RUN if [ "$INCLUDE_CHROMIUM" = "true" ]; then \
|
||||
playwright install chromium; \
|
||||
else \
|
||||
echo "Skipping Chromium installation in dev mode"; \
|
||||
fi
|
||||
|
||||
# Install GeckoDriver WebDriver and Firefox (if required)
|
||||
ARG GECKODRIVER_VERSION=v0.34.0
|
||||
ARG FIREFOX_VERSION=125.0.3
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
if [ "$INCLUDE_FIREFOX" = "true" ]; then \
|
||||
/docker/apt-install.sh wget bzip2 \
|
||||
&& wget -q https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O - | tar xfz - -C /usr/local/bin \
|
||||
&& wget -q https://download-installer.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2 -O - | tar xfj - -C /opt \
|
||||
&& ln -s /opt/firefox/firefox /usr/local/bin/firefox \
|
||||
&& apt-get autoremove -yqq --purge wget bzip2 && rm -rf /var/[log,tmp]/* /tmp/* /var/lib/apt/lists/* /var/cache/apt/archives/*; \
|
||||
else \
|
||||
echo "Skipping Firefox installation in dev mode"; \
|
||||
fi
|
||||
|
||||
# Install MySQL client dependencies
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
/docker/apt-install.sh default-libmysqlclient-dev
|
||||
# Debian libs needed for dev
|
||||
RUN /app/docker/apt-install.sh \
|
||||
git \
|
||||
pkg-config \
|
||||
default-libmysqlclient-dev
|
||||
|
||||
# Copy development requirements and install them
|
||||
COPY --chown=superset:superset requirements/development.txt requirements/
|
||||
RUN --mount=type=bind,source=./docker,target=/docker \
|
||||
--mount=type=cache,target=/root/.cache/pip \
|
||||
/docker/pip-install.sh --requires-build-essential -r requirements/development.txt
|
||||
COPY requirements/*.txt requirements/
|
||||
# Install Python dependencies using docker/pip-install.sh
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
/app/docker/pip-install.sh --requires-build-essential -r requirements/development.txt && \
|
||||
uv pip install .
|
||||
|
||||
RUN python -m compileall /app/superset
|
||||
|
||||
USER superset
|
||||
|
||||
@@ -232,6 +227,4 @@ USER superset
|
||||
######################################################################
|
||||
FROM lean AS ci
|
||||
|
||||
COPY --chown=superset:superset --chmod=755 ./docker/*.sh /app/docker/
|
||||
|
||||
CMD ["/app/docker/docker-ci.sh"]
|
||||
CMD ["/app/docker/entrypoints/docker-ci.sh"]
|
||||
|
||||
@@ -87,9 +87,6 @@ format: py-format js-format
|
||||
py-format: pre-commit
|
||||
pre-commit run black --all-files
|
||||
|
||||
py-lint: pre-commit
|
||||
pylint -j 0 superset
|
||||
|
||||
js-format:
|
||||
cd superset-frontend; npm run prettier
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ assists people when migrating to a new version.
|
||||
- [29798](https://github.com/apache/superset/pull/29798) Since 3.1.0, the intial schedule for an alert or report was mistakenly offset by the specified timezone's relation to UTC. The initial schedule should now begin at the correct time.
|
||||
- [30021](https://github.com/apache/superset/pull/30021) The `dev` layer in our Dockerfile no long includes firefox binaries, only Chromium to reduce bloat/docker-build-time.
|
||||
- [30099](https://github.com/apache/superset/pull/30099) Translations are no longer included in the default docker image builds. If your environment requires translations, you'll want to set the docker build arg `BUILD_TRANSACTION=true`.
|
||||
- [31262](https://github.com/apache/superset/pull/31262) NOTE: deprecated `pylint` in favor of `ruff` as our only python linter. Only affect development workflows positively (not the release itself). It should cover most important rules, be much faster, but some things linting rules that were enforced before may not be enforce in the exact same way as before.
|
||||
- [31173](https://github.com/apache/superset/pull/31173) Modified `fetch_csrf_token` to align with HTTP standards, particularly regarding how cookies are handled. If you encounter any issues related to CSRF functionality, please report them as a new issue and reference this PR for context.
|
||||
- [31385](https://github.com/apache/superset/pull/31385) Significant docker refactor, reducing access levels for the `superset` user, streamlining layer building, ...
|
||||
|
||||
### Potential Downtime
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
|
||||
COMPOSE_PROJECT_NAME=superset
|
||||
DEV_MODE=true
|
||||
|
||||
# database configurations (do not modify)
|
||||
DATABASE_DB=superset
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
# Make python interactive
|
||||
if [ "$DEV_MODE" == "true" ]; then
|
||||
echo "[DEV_MODE detected] Setting the superset package to be in editable mode"
|
||||
echo "RUN: uv pip install -e ."
|
||||
uv pip install -e .
|
||||
fi
|
||||
REQUIREMENTS_LOCAL="/app/docker/requirements-local.txt"
|
||||
# If Cypress run – overwrite the password for admin and export env variables
|
||||
if [ "$CYPRESS_CONFIG" == "true" ]; then
|
||||
@@ -29,10 +35,8 @@ fi
|
||||
# Make sure we have dev requirements installed
|
||||
#
|
||||
if [ -f "${REQUIREMENTS_LOCAL}" ]; then
|
||||
echo "Installing local overrides at ${REQUIREMENTS_LOCAL}"
|
||||
pip install --no-cache-dir -r "${REQUIREMENTS_LOCAL}"
|
||||
else
|
||||
echo "Skipping local overrides"
|
||||
echo "Installing python packages specified at ${REQUIREMENTS_LOCAL}"
|
||||
uv pip install --no-cache-dir -r "${REQUIREMENTS_LOCAL}"
|
||||
fi
|
||||
|
||||
case "${1}" in
|
||||
|
||||
+1
-11
@@ -30,15 +30,9 @@ fi
|
||||
|
||||
echo_step() {
|
||||
cat <<EOF
|
||||
|
||||
######################################################################
|
||||
|
||||
|
||||
Init Step ${1}/${STEP_CNT} [${2}] -- ${3}
|
||||
|
||||
|
||||
Docker Init Step ${1}/${STEP_CNT} [${2}] -- ${3}
|
||||
######################################################################
|
||||
|
||||
EOF
|
||||
}
|
||||
ADMIN_PASSWORD="${ADMIN_PASSWORD:-admin}"
|
||||
@@ -52,7 +46,6 @@ fi
|
||||
# Initialize the database
|
||||
echo_step "1" "Starting" "Applying DB migrations"
|
||||
superset db upgrade
|
||||
echo_step "1" "Complete" "Applying DB migrations"
|
||||
|
||||
# Create an admin user
|
||||
echo_step "2" "Starting" "Setting up admin user ( admin / $ADMIN_PASSWORD )"
|
||||
@@ -62,11 +55,9 @@ superset fab create-admin \
|
||||
--lastname Admin \
|
||||
--email admin@superset.com \
|
||||
--password "$ADMIN_PASSWORD"
|
||||
echo_step "2" "Complete" "Setting up admin user"
|
||||
# Create default roles and permissions
|
||||
echo_step "3" "Starting" "Setting up roles and perms"
|
||||
superset init
|
||||
echo_step "3" "Complete" "Setting up roles and perms"
|
||||
|
||||
if [ "$SUPERSET_LOAD_EXAMPLES" = "yes" ]; then
|
||||
# Load some data to play with
|
||||
@@ -78,5 +69,4 @@ if [ "$SUPERSET_LOAD_EXAMPLES" = "yes" ]; then
|
||||
else
|
||||
superset load_examples --force
|
||||
fi
|
||||
echo_step "4" "Complete" "Loading examples"
|
||||
fi
|
||||
|
||||
@@ -47,10 +47,10 @@ fi
|
||||
# Choose whether to use pip cache
|
||||
if $USE_CACHE; then
|
||||
echo "Using pip cache..."
|
||||
uv pip install --system "${ARGS[@]}"
|
||||
uv pip install "${ARGS[@]}"
|
||||
else
|
||||
echo "Disabling pip cache..."
|
||||
uv pip install --system --no-cache-dir "${ARGS[@]}"
|
||||
uv pip install --no-cache-dir "${ARGS[@]}"
|
||||
fi
|
||||
|
||||
# Remove build-essential if it was installed
|
||||
|
||||
@@ -103,6 +103,7 @@ WEBDRIVER_BASEURL = "http://superset:8088/" # When using docker compose baseurl
|
||||
# The base URL for the email report hyperlinks.
|
||||
WEBDRIVER_BASEURL_USER_FRIENDLY = WEBDRIVER_BASEURL
|
||||
SQLLAB_CTAS_NO_LIMIT = True
|
||||
LOG_LEVEL = logging.INFO
|
||||
|
||||
#
|
||||
# Optionally import superset_config_docker.py (which will have been included on
|
||||
|
||||
@@ -478,37 +478,7 @@ A series of checks will now run when you make a git commit.
|
||||
|
||||
## Linting
|
||||
|
||||
### Python
|
||||
|
||||
We use [Pylint](https://pylint.org/) for linting which can be invoked via:
|
||||
|
||||
```bash
|
||||
pylint
|
||||
```
|
||||
|
||||
In terms of best practices please avoid blanket disabling of Pylint messages globally (via `.pylintrc`) or top-level within the file header, albeit there being a few exceptions. Disabling should occur inline as it prevents masking issues and provides context as to why said message is disabled.
|
||||
|
||||
Additionally, the Python code is auto-formatted using [Black](https://github.com/python/black) which
|
||||
is configured as a pre-commit hook. There are also numerous [editor integrations](https://black.readthedocs.io/en/stable/integrations/editors.html)
|
||||
|
||||
### TypeScript
|
||||
|
||||
```bash
|
||||
cd superset-frontend
|
||||
npm ci
|
||||
# run eslint checks
|
||||
npm run eslint -- .
|
||||
# run tsc (typescript) checks
|
||||
npm run type
|
||||
```
|
||||
|
||||
If using the eslint extension with vscode, put the following in your workspace `settings.json` file:
|
||||
|
||||
```json
|
||||
"eslint.workingDirectories": [
|
||||
"superset-frontend"
|
||||
]
|
||||
```
|
||||
See [how tos](/docs/contributing/howtos#linting)
|
||||
|
||||
|
||||
## GitHub Actions and `act`
|
||||
|
||||
@@ -571,13 +571,9 @@ pybabel compile -d superset/translations
|
||||
|
||||
### Python
|
||||
|
||||
We use [Pylint](https://pylint.org/) and [ruff](https://github.com/astral-sh/ruff)
|
||||
for linting which can be invoked via:
|
||||
We use [ruff](https://github.com/astral-sh/ruff) for linting which can be invoked via:
|
||||
|
||||
```
|
||||
# Run pylint
|
||||
pylint superset/
|
||||
|
||||
# auto-reformat using ruff
|
||||
ruff format
|
||||
|
||||
@@ -588,11 +584,8 @@ ruff check
|
||||
ruff check --fix
|
||||
```
|
||||
|
||||
|
||||
In terms of best practices please avoid blanket disabling of Pylint messages globally
|
||||
(via `.pylintrc`) or top-level within the file header, albeit there being a few exceptions.
|
||||
Disabling should occur inline as it prevents masking issues and provides context as to why
|
||||
said message is disabled.
|
||||
Ruff configuration is located in our
|
||||
(pyproject.toml)[https://github.com/apache/superset/blob/master/pyproject.toml] file
|
||||
|
||||
All this is configured to run in pre-commit hooks, which we encourage you to setup
|
||||
with `pre-commit install`
|
||||
|
||||
@@ -9,6 +9,7 @@ sidebar_position: 2
|
||||
| CVE-2024-53947 | Improper SQL authorisation, parse for specific postgres functions | < 4.1.0 |
|
||||
| CVE-2024-53948 | Error verbosity exposes metadata in analytics databases | < 4.1.0 |
|
||||
| CVE-2024-53949 | Lower privilege users are able to create Role when FAB_ADD_SECURITY_API is enabled | < 4.1.0 |
|
||||
| CVE-2024-55633 | SQLLab Improper readonly query validation allows unauthorized write access | < 4.1.0 |
|
||||
|
||||
#### Version 4.0.2
|
||||
|
||||
|
||||
Vendored
+5083
-903
File diff suppressed because it is too large
Load Diff
+21
-4
@@ -70,7 +70,11 @@ dependencies = [
|
||||
"nh3>=0.2.11, <0.3",
|
||||
"numpy==1.23.5",
|
||||
"packaging",
|
||||
"pandas[excel,performance]>=2.0.3, <2.1",
|
||||
# --------------------------
|
||||
# pandas and related (wanting pandas[performance] without numba as it's 100+MB and not needed)
|
||||
"pandas[excel]>=2.0.3, <2.1",
|
||||
"bottleneck",
|
||||
# --------------------------
|
||||
"parsedatetime",
|
||||
"paramiko>=3.4.0",
|
||||
"pgsanity",
|
||||
@@ -193,7 +197,6 @@ development = [
|
||||
"psutil",
|
||||
"pyfakefs",
|
||||
"pyinstrument>=4.0.2,<5",
|
||||
"pylint",
|
||||
"pytest<8.0.0", # hairy issue with pytest >=8 where current_app proxies are not set in time
|
||||
"pytest-cov",
|
||||
"pytest-mock",
|
||||
@@ -286,11 +289,25 @@ select = [
|
||||
"E4",
|
||||
"E7",
|
||||
"E9",
|
||||
"F",
|
||||
"PT009",
|
||||
"TRY201",
|
||||
# TODO add these rules in follow up PR
|
||||
# "B",
|
||||
# "C",
|
||||
# "E",
|
||||
# "F",
|
||||
#"F",
|
||||
# "I",
|
||||
# "N",
|
||||
# "PT",
|
||||
# "Q",
|
||||
# "S",
|
||||
# "T",
|
||||
#"W",
|
||||
]
|
||||
ignore = [
|
||||
"S101",
|
||||
]
|
||||
ignore = []
|
||||
|
||||
extend-select = ["I"]
|
||||
|
||||
|
||||
+3
-10
@@ -35,7 +35,7 @@ billiard==4.2.1
|
||||
blinker==1.9.0
|
||||
# via flask
|
||||
bottleneck==1.4.2
|
||||
# via pandas
|
||||
# via apache-superset
|
||||
brotli==1.1.0
|
||||
# via flask-compress
|
||||
cachelib==0.9.0
|
||||
@@ -194,8 +194,6 @@ korean-lunar-calendar==0.3.1
|
||||
# via holidays
|
||||
limits==3.13.0
|
||||
# via flask-limiter
|
||||
llvmlite==0.43.0
|
||||
# via numba
|
||||
mako==1.3.6
|
||||
# via
|
||||
# alembic
|
||||
@@ -224,17 +222,12 @@ msgspec==0.18.6
|
||||
# via flask-session
|
||||
nh3==0.2.19
|
||||
# via apache-superset
|
||||
numba==0.60.0
|
||||
# via pandas
|
||||
numexpr==2.10.2
|
||||
# via
|
||||
# -r requirements/base.in
|
||||
# pandas
|
||||
# via -r requirements/base.in
|
||||
numpy==1.23.5
|
||||
# via
|
||||
# apache-superset
|
||||
# bottleneck
|
||||
# numba
|
||||
# numexpr
|
||||
# pandas
|
||||
# pyarrow
|
||||
@@ -254,7 +247,7 @@ packaging==24.2
|
||||
# marshmallow
|
||||
# marshmallow-sqlalchemy
|
||||
# shillelagh
|
||||
pandas[excel,performance]==2.0.3
|
||||
pandas[excel]==2.0.3
|
||||
# via apache-superset
|
||||
paramiko==3.5.0
|
||||
# via
|
||||
|
||||
@@ -8,10 +8,8 @@
|
||||
-r base.txt
|
||||
-e file:.
|
||||
# via
|
||||
# -r requirements/base.in
|
||||
# -r /Users/max/code/superset/requirements/base.in
|
||||
# -r requirements/development.in
|
||||
astroid==3.1.0
|
||||
# via pylint
|
||||
build==1.2.1
|
||||
# via pip-tools
|
||||
cfgv==3.4.0
|
||||
@@ -26,8 +24,6 @@ cycler==0.12.1
|
||||
# via matplotlib
|
||||
db-dtypes==1.3.1
|
||||
# via pandas-gbq
|
||||
dill==0.3.9
|
||||
# via pylint
|
||||
distlib==0.3.8
|
||||
# via virtualenv
|
||||
docker==7.0.0
|
||||
@@ -85,8 +81,6 @@ identify==2.5.36
|
||||
# via pre-commit
|
||||
iniconfig==2.0.0
|
||||
# via pytest
|
||||
isort==5.12.0
|
||||
# via pylint
|
||||
jsonschema-spec==0.1.6
|
||||
# via openapi-spec-validator
|
||||
kiwisolver==1.4.7
|
||||
@@ -95,8 +89,6 @@ lazy-object-proxy==1.10.0
|
||||
# via openapi-spec-validator
|
||||
matplotlib==3.9.0
|
||||
# via prophet
|
||||
mccabe==0.7.0
|
||||
# via pylint
|
||||
mysqlclient==2.2.6
|
||||
# via apache-superset
|
||||
nodeenv==1.8.0
|
||||
@@ -158,8 +150,6 @@ pyhive[presto]==0.7.0
|
||||
# via apache-superset
|
||||
pyinstrument==4.4.0
|
||||
# via apache-superset
|
||||
pylint==3.1.0
|
||||
# via apache-superset
|
||||
pyproject-hooks==1.2.0
|
||||
# via
|
||||
# build
|
||||
@@ -192,10 +182,7 @@ tomli==2.1.0
|
||||
# build
|
||||
# coverage
|
||||
# pip-tools
|
||||
# pylint
|
||||
# pytest
|
||||
tomlkit==0.13.2
|
||||
# via pylint
|
||||
toposort==1.10
|
||||
# via pip-compile-multi
|
||||
tqdm==4.67.1
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
babel
|
||||
@@ -0,0 +1,9 @@
|
||||
# SHA1:cad160f3d4cd7c33896f42a479eeaa1b5bedc5fb
|
||||
#
|
||||
# This file is autogenerated by pip-compile-multi
|
||||
# To update, run:
|
||||
#
|
||||
# pip-compile-multi
|
||||
#
|
||||
babel==2.16.0
|
||||
# via -r requirements/translations.in
|
||||
@@ -51,6 +51,7 @@ const Styles = styled.div<PivotTableStylesProps>`
|
||||
width: ${
|
||||
typeof width === 'string' ? parseInt(width, 10) : width - margin * 2
|
||||
}px;
|
||||
white-space: nowrap;
|
||||
`}
|
||||
`;
|
||||
|
||||
|
||||
@@ -421,9 +421,7 @@ export function postStopQuery(query) {
|
||||
})
|
||||
.then(() => dispatch(stopQuery(query)))
|
||||
.then(() => dispatch(addSuccessToast(t('Query was stopped.'))))
|
||||
.catch(() =>
|
||||
dispatch(addDangerToast(t('Failed at stopping query. %s', query.id))),
|
||||
);
|
||||
.catch(() => dispatch(addDangerToast(t('Failed to stop query.'))));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,10 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { useMemo } from 'react';
|
||||
import { useMemo, ReactNode } from 'react';
|
||||
import moment from 'moment';
|
||||
import Card from 'src/components/Card';
|
||||
import ProgressBar from 'src/components/ProgressBar';
|
||||
import Label from 'src/components/Label';
|
||||
import { t, useTheme, QueryResponse } from '@superset-ui/core';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
@@ -35,6 +34,7 @@ import TableView from 'src/components/TableView';
|
||||
import Button from 'src/components/Button';
|
||||
import { fDuration } from 'src/utils/dates';
|
||||
import Icons from 'src/components/Icons';
|
||||
import Label from 'src/components/Label';
|
||||
import { Tooltip } from 'src/components/Tooltip';
|
||||
import { SqlLabRootState } from 'src/SqlLab/types';
|
||||
import ModalTrigger from 'src/components/ModalTrigger';
|
||||
@@ -44,11 +44,16 @@ import HighlightedSql from '../HighlightedSql';
|
||||
import { StaticPosition, verticalAlign, StyledTooltip } from './styles';
|
||||
|
||||
interface QueryTableQuery
|
||||
extends Omit<QueryResponse, 'state' | 'sql' | 'progress' | 'results'> {
|
||||
extends Omit<
|
||||
QueryResponse,
|
||||
'state' | 'sql' | 'progress' | 'results' | 'duration' | 'started'
|
||||
> {
|
||||
state?: Record<string, any>;
|
||||
sql?: Record<string, any>;
|
||||
progress?: Record<string, any>;
|
||||
results?: Record<string, any>;
|
||||
duration?: ReactNode;
|
||||
started?: ReactNode;
|
||||
}
|
||||
|
||||
interface QueryTableProps {
|
||||
@@ -125,55 +130,95 @@ const QueryTable = ({
|
||||
const statusAttributes = {
|
||||
success: {
|
||||
config: {
|
||||
icon: <Icons.Check iconColor={theme.colors.success.base} />,
|
||||
icon: (
|
||||
<Icons.CheckOutlined
|
||||
iconColor={theme.colors.success.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
// icon: <Icons.Edit iconSize="xl" />,
|
||||
label: t('Success'),
|
||||
},
|
||||
},
|
||||
failed: {
|
||||
config: {
|
||||
icon: <Icons.XSmall iconColor={theme.colors.error.base} />,
|
||||
icon: (
|
||||
<Icons.CloseOutlined
|
||||
iconColor={theme.colors.error.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Failed'),
|
||||
},
|
||||
},
|
||||
stopped: {
|
||||
config: {
|
||||
icon: <Icons.XSmall iconColor={theme.colors.error.base} />,
|
||||
icon: (
|
||||
<Icons.CloseOutlined
|
||||
iconColor={theme.colors.error.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Failed'),
|
||||
},
|
||||
},
|
||||
running: {
|
||||
config: {
|
||||
icon: <Icons.Running iconColor={theme.colors.primary.base} />,
|
||||
icon: (
|
||||
<Icons.LoadingOutlined
|
||||
iconColor={theme.colors.primary.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Running'),
|
||||
},
|
||||
},
|
||||
fetching: {
|
||||
config: {
|
||||
icon: <Icons.Queued iconColor={theme.colors.primary.base} />,
|
||||
icon: (
|
||||
<Icons.LoadingOutlined
|
||||
iconColor={theme.colors.primary.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Fetching'),
|
||||
},
|
||||
},
|
||||
timed_out: {
|
||||
config: {
|
||||
icon: <Icons.Offline iconColor={theme.colors.grayscale.light1} />,
|
||||
icon: (
|
||||
<Icons.Clock iconColor={theme.colors.error.base} iconSize="m" />
|
||||
),
|
||||
label: t('Offline'),
|
||||
},
|
||||
},
|
||||
scheduled: {
|
||||
config: {
|
||||
icon: <Icons.Queued iconColor={theme.colors.grayscale.base} />,
|
||||
icon: (
|
||||
<Icons.LoadingOutlined
|
||||
iconColor={theme.colors.warning.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Scheduled'),
|
||||
},
|
||||
},
|
||||
pending: {
|
||||
config: {
|
||||
icon: <Icons.Queued iconColor={theme.colors.grayscale.base} />,
|
||||
icon: (
|
||||
<Icons.LoadingOutlined
|
||||
iconColor={theme.colors.warning.base}
|
||||
iconSize="m"
|
||||
/>
|
||||
),
|
||||
label: t('Scheduled'),
|
||||
},
|
||||
},
|
||||
error: {
|
||||
config: {
|
||||
icon: <Icons.Error iconColor={theme.colors.error.base} />,
|
||||
icon: (
|
||||
<Icons.Error iconColor={theme.colors.error.base} iconSize="m" />
|
||||
),
|
||||
label: t('Unknown Status'),
|
||||
},
|
||||
},
|
||||
@@ -187,16 +232,10 @@ const QueryTable = ({
|
||||
const status = statusAttributes[state] || statusAttributes.error;
|
||||
|
||||
if (q.endDttm) {
|
||||
q.duration = fDuration(q.startDttm, q.endDttm);
|
||||
q.duration = (
|
||||
<Label monospace>{fDuration(q.startDttm, q.endDttm)}</Label>
|
||||
);
|
||||
}
|
||||
const time = moment(q.startDttm).format().split('T');
|
||||
q.time = (
|
||||
<div>
|
||||
<span>
|
||||
{time[0]} <br /> {time[1]}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
q.user = (
|
||||
<Button
|
||||
buttonSize="small"
|
||||
@@ -215,7 +254,9 @@ const QueryTable = ({
|
||||
{q.db}
|
||||
</Button>
|
||||
);
|
||||
q.started = moment(q.startDttm).format('L HH:mm:ss');
|
||||
q.started = (
|
||||
<Label monospace>{moment(q.startDttm).format('L HH:mm:ss')}</Label>
|
||||
);
|
||||
q.querylink = (
|
||||
<Button
|
||||
buttonSize="small"
|
||||
@@ -241,9 +282,9 @@ const QueryTable = ({
|
||||
<ModalTrigger
|
||||
className="ResultsModal"
|
||||
triggerNode={
|
||||
<Label type="info" className="pointer">
|
||||
<Button buttonSize="xsmall" buttonStyle="tertiary">
|
||||
{t('View')}
|
||||
</Label>
|
||||
</Button>
|
||||
}
|
||||
modalTitle={t('Data preview')}
|
||||
beforeOpen={() => openAsyncResults(query, displayLimit)}
|
||||
@@ -275,9 +316,7 @@ const QueryTable = ({
|
||||
<ProgressBar percent={parseInt(progress.toFixed(0), 10)} striped />
|
||||
);
|
||||
q.state = (
|
||||
<Tooltip title={status.config.label} placement="bottom">
|
||||
<span>{status.config.icon}</span>
|
||||
</Tooltip>
|
||||
<Tooltip title={status.config.label}>{status.config.icon}</Tooltip>
|
||||
);
|
||||
q.actions = (
|
||||
<div>
|
||||
@@ -287,6 +326,7 @@ const QueryTable = ({
|
||||
'Overwrite text in the editor with a query on this table',
|
||||
)}
|
||||
placement="top"
|
||||
className="pointer"
|
||||
>
|
||||
<Icons.Edit iconSize="xl" />
|
||||
</StyledTooltip>
|
||||
@@ -294,6 +334,7 @@ const QueryTable = ({
|
||||
onClick={() => openQueryInNewTab(query)}
|
||||
tooltip={t('Run query in a new tab')}
|
||||
placement="top"
|
||||
className="pointer"
|
||||
>
|
||||
<Icons.PlusCircleOutlined iconSize="xl" css={verticalAlign} />
|
||||
</StyledTooltip>
|
||||
@@ -301,6 +342,7 @@ const QueryTable = ({
|
||||
<StyledTooltip
|
||||
tooltip={t('Remove query from log')}
|
||||
onClick={() => dispatch(removeQuery(query))}
|
||||
className="pointer"
|
||||
>
|
||||
<Icons.Trash iconSize="xl" />
|
||||
</StyledTooltip>
|
||||
|
||||
@@ -44,10 +44,19 @@ const IconBlock = styled.div`
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: ${({ theme }) => theme.gridUnit * 2}px;
|
||||
|
||||
span {
|
||||
margin-top: ${({ theme }) =>
|
||||
2 * theme.gridUnit}px; // Add spacing between icon and name
|
||||
font-size: ${({ theme }) =>
|
||||
theme.typography.sizes.m}; // Optional: adjust font size for elegance
|
||||
color: ${({ theme }) =>
|
||||
theme.colors.grayscale.base}; // Optional: subtle color for the name
|
||||
}
|
||||
`;
|
||||
|
||||
export const InteractiveIcons = ({
|
||||
showNames,
|
||||
showNames = true,
|
||||
...rest
|
||||
}: IconType & { showNames: boolean }) => (
|
||||
<IconSet>
|
||||
@@ -56,7 +65,7 @@ export const InteractiveIcons = ({
|
||||
return (
|
||||
<IconBlock key={k}>
|
||||
<IconComponent {...rest} />
|
||||
{showNames && k}
|
||||
{showNames && <span>{k}</span>}
|
||||
</IconBlock>
|
||||
);
|
||||
})}
|
||||
|
||||
@@ -55,9 +55,13 @@ export const LabelGallery = () => (
|
||||
);
|
||||
|
||||
export const InteractiveLabel = (args: any) => {
|
||||
const { hasOnClick, label, ...rest } = args;
|
||||
const { hasOnClick, label, monospace, ...rest } = args;
|
||||
return (
|
||||
<Label onClick={hasOnClick ? action('clicked') : undefined} {...rest}>
|
||||
<Label
|
||||
onClick={hasOnClick ? action('clicked') : undefined}
|
||||
monospace={monospace}
|
||||
{...rest}
|
||||
>
|
||||
{label}
|
||||
</Label>
|
||||
);
|
||||
@@ -66,4 +70,5 @@ export const InteractiveLabel = (args: any) => {
|
||||
InteractiveLabel.args = {
|
||||
hasOnClick: true,
|
||||
label: 'Example',
|
||||
monospace: true,
|
||||
};
|
||||
|
||||
@@ -46,12 +46,20 @@ export interface LabelProps extends HTMLAttributes<HTMLSpanElement> {
|
||||
style?: CSSProperties;
|
||||
children?: ReactNode;
|
||||
role?: string;
|
||||
monospace?: boolean;
|
||||
}
|
||||
|
||||
export default function Label(props: LabelProps) {
|
||||
const theme = useTheme();
|
||||
const { colors, transitionTiming } = theme;
|
||||
const { type = 'default', onClick, children, ...rest } = props;
|
||||
const {
|
||||
type = 'default',
|
||||
monospace = false,
|
||||
style,
|
||||
onClick,
|
||||
children,
|
||||
...rest
|
||||
} = props;
|
||||
const {
|
||||
alert,
|
||||
primary,
|
||||
@@ -89,37 +97,41 @@ export default function Label(props: LabelProps) {
|
||||
} else {
|
||||
baseColor = primary;
|
||||
}
|
||||
|
||||
backgroundColor = baseColor.base;
|
||||
backgroundColorHover = onClick ? baseColor.dark1 : baseColor.base;
|
||||
borderColor = onClick ? baseColor.dark1 : 'transparent';
|
||||
borderColorHover = onClick ? baseColor.dark2 : 'transparent';
|
||||
}
|
||||
const css = {
|
||||
transition: `background-color ${transitionTiming}s`,
|
||||
whiteSpace: 'nowrap',
|
||||
cursor: onClick ? 'pointer' : 'default',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
borderRadius: 21,
|
||||
padding: '0.35em 0.8em',
|
||||
lineHeight: 1,
|
||||
color,
|
||||
maxWidth: '100%',
|
||||
'&:hover': {
|
||||
backgroundColor: backgroundColorHover,
|
||||
borderColor: borderColorHover,
|
||||
opacity: 1,
|
||||
},
|
||||
};
|
||||
if (monospace) {
|
||||
css['font-family'] = theme.typography.families.monospace;
|
||||
}
|
||||
|
||||
return (
|
||||
<Tag
|
||||
onClick={onClick}
|
||||
role={onClick ? 'button' : undefined}
|
||||
style={style}
|
||||
{...rest}
|
||||
css={{
|
||||
transition: `background-color ${transitionTiming}s`,
|
||||
whiteSpace: 'nowrap',
|
||||
cursor: onClick ? 'pointer' : 'default',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
backgroundColor,
|
||||
borderColor,
|
||||
borderRadius: 21,
|
||||
padding: '0.35em 0.8em',
|
||||
lineHeight: 1,
|
||||
color,
|
||||
maxWidth: '100%',
|
||||
'&:hover': {
|
||||
backgroundColor: backgroundColorHover,
|
||||
borderColor: borderColorHover,
|
||||
opacity: 1,
|
||||
},
|
||||
}}
|
||||
css={css}
|
||||
>
|
||||
{children}
|
||||
</Tag>
|
||||
|
||||
@@ -73,8 +73,9 @@ import {
|
||||
isLabelsColorMapSynced,
|
||||
getColorSchemeDomain,
|
||||
getColorNamespace,
|
||||
getLabelsColorMapEntries,
|
||||
getFreshLabelsColorMapEntries,
|
||||
getFreshSharedLabels,
|
||||
getDynamicLabelsColors,
|
||||
} from '../../utils/colorScheme';
|
||||
|
||||
export const SET_UNSAVED_CHANGES = 'SET_UNSAVED_CHANGES';
|
||||
@@ -253,15 +254,18 @@ export function setDashboardSharedLabelsColorsSynced() {
|
||||
return { type: SET_DASHBOARD_SHARED_LABELS_COLORS_SYNCED };
|
||||
}
|
||||
|
||||
export const setDashboardMetadata = updatedMetadata => async dispatch => {
|
||||
dispatch(
|
||||
dashboardInfoChanged({
|
||||
metadata: {
|
||||
...updatedMetadata,
|
||||
},
|
||||
}),
|
||||
);
|
||||
};
|
||||
export const setDashboardMetadata =
|
||||
updatedMetadata => async (dispatch, getState) => {
|
||||
const { dashboardInfo } = getState();
|
||||
dispatch(
|
||||
dashboardInfoChanged({
|
||||
metadata: {
|
||||
...(dashboardInfo?.metadata || {}),
|
||||
...updatedMetadata,
|
||||
},
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export function saveDashboardRequest(data, id, saveType) {
|
||||
return (dispatch, getState) => {
|
||||
@@ -320,7 +324,7 @@ export function saveDashboardRequest(data, id, saveType) {
|
||||
expanded_slices: data.metadata?.expanded_slices || {},
|
||||
label_colors: customLabelsColor,
|
||||
shared_label_colors: getFreshSharedLabels(sharedLabelsColor),
|
||||
map_label_colors: getLabelsColorMapEntries(customLabelsColor),
|
||||
map_label_colors: getFreshLabelsColorMapEntries(customLabelsColor),
|
||||
refresh_frequency: data.metadata?.refresh_frequency || 0,
|
||||
timed_refresh_immune_slices:
|
||||
data.metadata?.timed_refresh_immune_slices || [],
|
||||
@@ -719,11 +723,18 @@ export function setDatasetsStatus(status) {
|
||||
};
|
||||
}
|
||||
|
||||
const storeDashboardMetadata = async (id, metadata) =>
|
||||
const storeDashboardColorConfig = async (id, metadata) =>
|
||||
SupersetClient.put({
|
||||
endpoint: `/api/v1/dashboard/${id}`,
|
||||
endpoint: `/api/v1/dashboard/${id}/colors?mark_updated=false`,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ json_metadata: JSON.stringify(metadata) }),
|
||||
body: JSON.stringify({
|
||||
color_namespace: metadata.color_namespace,
|
||||
color_scheme: metadata.color_scheme,
|
||||
color_scheme_domain: metadata.color_scheme_domain || [],
|
||||
shared_label_colors: metadata.shared_label_colors || [],
|
||||
map_label_colors: metadata.map_label_colors || {},
|
||||
label_colors: metadata.label_colors || {},
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -742,7 +753,7 @@ export const persistDashboardLabelsColor = () => async (dispatch, getState) => {
|
||||
if (labelsColorMapMustSync || sharedLabelsColorsMustSync) {
|
||||
dispatch(setDashboardLabelsColorMapSynced());
|
||||
dispatch(setDashboardSharedLabelsColorsSynced());
|
||||
storeDashboardMetadata(id, metadata);
|
||||
storeDashboardColorConfig(id, metadata);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -756,7 +767,6 @@ export const persistDashboardLabelsColor = () => async (dispatch, getState) => {
|
||||
*/
|
||||
export const applyDashboardLabelsColorOnLoad = metadata => async dispatch => {
|
||||
try {
|
||||
const updatedMetadata = { ...metadata };
|
||||
const customLabelsColor = metadata.label_colors || {};
|
||||
let hasChanged = false;
|
||||
|
||||
@@ -764,11 +774,14 @@ export const applyDashboardLabelsColorOnLoad = metadata => async dispatch => {
|
||||
const sharedLabels = metadata.shared_label_colors || [];
|
||||
if (!Array.isArray(sharedLabels) && Object.keys(sharedLabels).length > 0) {
|
||||
hasChanged = true;
|
||||
updatedMetadata.shared_label_colors = [];
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
shared_label_colors: [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
// backward compatibility of map_label_colors
|
||||
const hasMapLabelColors =
|
||||
Object.keys(metadata.map_label_colors || {}).length > 0;
|
||||
const hasMapLabelColors = !!metadata.map_label_colors;
|
||||
|
||||
let updatedScheme = metadata.color_scheme;
|
||||
const categoricalSchemes = getCategoricalSchemeRegistry();
|
||||
@@ -780,11 +793,14 @@ export const applyDashboardLabelsColorOnLoad = metadata => async dispatch => {
|
||||
const defaultScheme = categoricalSchemes.defaultKey;
|
||||
const fallbackScheme = defaultScheme?.toString() || 'supersetColors';
|
||||
hasChanged = true;
|
||||
|
||||
updatedScheme = fallbackScheme;
|
||||
updatedMetadata.color_scheme = updatedScheme;
|
||||
|
||||
dispatch(setColorScheme(updatedScheme));
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
color_scheme: updatedScheme,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// the stored color domain registry and fresh might differ at this point
|
||||
@@ -795,24 +811,28 @@ export const applyDashboardLabelsColorOnLoad = metadata => async dispatch => {
|
||||
|
||||
if (!isEqual(freshColorSchemeDomain, currentColorSchemeDomain)) {
|
||||
hasChanged = true;
|
||||
updatedMetadata.color_scheme_domain = freshColorSchemeDomain;
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
color_scheme_domain: freshColorSchemeDomain,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
// if color scheme is invalid or map is missing, apply a fresh color map
|
||||
// if valid, apply the stored map to keep consistency across refreshes
|
||||
const shouldGoFresh = !hasMapLabelColors || hasInvalidColorScheme;
|
||||
applyColors(updatedMetadata, shouldGoFresh);
|
||||
applyColors(metadata, shouldGoFresh);
|
||||
|
||||
if (shouldGoFresh) {
|
||||
// a fresh color map has been applied
|
||||
// needs to be stored for consistency
|
||||
hasChanged = true;
|
||||
updatedMetadata.map_label_colors =
|
||||
getLabelsColorMapEntries(customLabelsColor);
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
map_label_colors: getFreshLabelsColorMapEntries(customLabelsColor),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (hasChanged) {
|
||||
dispatch(setDashboardMetadata(updatedMetadata));
|
||||
dispatch(setDashboardLabelsColorMapSync());
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -832,19 +852,28 @@ export const ensureSyncedLabelsColorMap = metadata => (dispatch, getState) => {
|
||||
const {
|
||||
dashboardState: { labelsColorMapMustSync },
|
||||
} = getState();
|
||||
const updatedMetadata = { ...metadata };
|
||||
const customLabelsColor = metadata.label_colors || {};
|
||||
const isMapSynced = isLabelsColorMapSynced(metadata);
|
||||
const mustSync = !isMapSynced;
|
||||
const fullLabelsColors = getDynamicLabelsColors(
|
||||
metadata.map_label_colors || {},
|
||||
customLabelsColor,
|
||||
);
|
||||
const freshColorMapEntries =
|
||||
getFreshLabelsColorMapEntries(customLabelsColor);
|
||||
const isMapSynced = isLabelsColorMapSynced(
|
||||
fullLabelsColors,
|
||||
freshColorMapEntries,
|
||||
customLabelsColor,
|
||||
);
|
||||
|
||||
if (mustSync) {
|
||||
const freshestColorMapEntries =
|
||||
getLabelsColorMapEntries(customLabelsColor);
|
||||
updatedMetadata.map_label_colors = freshestColorMapEntries;
|
||||
dispatch(setDashboardMetadata(updatedMetadata));
|
||||
if (!isMapSynced) {
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
map_label_colors: freshColorMapEntries,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (mustSync && !labelsColorMapMustSync) {
|
||||
if (!isMapSynced && !labelsColorMapMustSync) {
|
||||
// prepare to persist the just applied labels color map
|
||||
dispatch(setDashboardLabelsColorMapSync());
|
||||
}
|
||||
@@ -867,7 +896,6 @@ export const ensureSyncedSharedLabelsColors =
|
||||
const {
|
||||
dashboardState: { sharedLabelsColorsMustSync },
|
||||
} = getState();
|
||||
const updatedMetadata = { ...metadata };
|
||||
const sharedLabelsColors = enforceSharedLabelsColorsArray(
|
||||
metadata.shared_label_colors,
|
||||
);
|
||||
@@ -875,15 +903,17 @@ export const ensureSyncedSharedLabelsColors =
|
||||
forceFresh ? [] : sharedLabelsColors,
|
||||
);
|
||||
const isSharedLabelsColorsSynced = isEqual(
|
||||
sharedLabelsColors,
|
||||
freshLabelsColors,
|
||||
sharedLabelsColors.sort(),
|
||||
freshLabelsColors.sort(),
|
||||
);
|
||||
|
||||
const mustSync = !isSharedLabelsColorsSynced;
|
||||
|
||||
if (mustSync) {
|
||||
updatedMetadata.shared_label_colors = freshLabelsColors;
|
||||
dispatch(setDashboardMetadata(updatedMetadata));
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
shared_label_colors: freshLabelsColors,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (mustSync && !sharedLabelsColorsMustSync) {
|
||||
@@ -901,77 +931,78 @@ export const ensureSyncedSharedLabelsColors =
|
||||
* @param {*} renderedChartIds - the charts that have finished rendering
|
||||
* @returns void
|
||||
*/
|
||||
export const updateDashboardLabelsColor =
|
||||
renderedChartIds => (dispatch, getState) => {
|
||||
try {
|
||||
const {
|
||||
dashboardInfo: { metadata },
|
||||
charts,
|
||||
} = getState();
|
||||
const colorScheme = metadata.color_scheme;
|
||||
const labelsColorMapInstance = getLabelsColorMap();
|
||||
const fullLabelsColors = metadata.map_label_colors || {};
|
||||
const sharedLabelsColors = enforceSharedLabelsColorsArray(
|
||||
metadata.shared_label_colors,
|
||||
);
|
||||
const customLabelsColors = metadata.label_colors || {};
|
||||
export const updateDashboardLabelsColor = renderedChartIds => (_, getState) => {
|
||||
try {
|
||||
const {
|
||||
dashboardInfo: { metadata },
|
||||
charts,
|
||||
} = getState();
|
||||
const colorScheme = metadata.color_scheme;
|
||||
const labelsColorMapInstance = getLabelsColorMap();
|
||||
const sharedLabelsColors = enforceSharedLabelsColorsArray(
|
||||
metadata.shared_label_colors,
|
||||
);
|
||||
const customLabelsColors = metadata.label_colors || {};
|
||||
const fullLabelsColors = getDynamicLabelsColors(
|
||||
metadata.map_label_colors || {},
|
||||
customLabelsColors,
|
||||
);
|
||||
|
||||
// for dashboards with no color scheme, the charts should always use their individual schemes
|
||||
// this logic looks for unique labels (not shared across multiple charts) of each rendered chart
|
||||
// it applies a new color to those unique labels when the applied scheme is not up to date
|
||||
// while leaving shared label colors and custom label colors intact for color consistency
|
||||
const shouldReset = [];
|
||||
if (renderedChartIds.length > 0) {
|
||||
const sharedLabelsSet = new Set(sharedLabelsColors);
|
||||
renderedChartIds.forEach(id => {
|
||||
const chart = charts[id];
|
||||
const formData = chart.form_data || chart.latestQueryFormData;
|
||||
// ensure charts have their original color scheme always available
|
||||
labelsColorMapInstance.setOwnColorScheme(
|
||||
formData.slice_id,
|
||||
formData.color_scheme,
|
||||
);
|
||||
// for dashboards with no color scheme, the charts should always use their individual schemes
|
||||
// this logic looks for unique labels (not shared across multiple charts) of each rendered chart
|
||||
// it applies a new color to those unique labels when the applied scheme is not up to date
|
||||
// while leaving shared label colors and custom label colors intact for color consistency
|
||||
const shouldReset = [];
|
||||
if (renderedChartIds.length > 0) {
|
||||
const sharedLabelsSet = new Set(sharedLabelsColors);
|
||||
renderedChartIds.forEach(id => {
|
||||
const chart = charts[id];
|
||||
const formData = chart.form_data || chart.latestQueryFormData;
|
||||
// ensure charts have their original color scheme always available
|
||||
labelsColorMapInstance.setOwnColorScheme(
|
||||
formData.slice_id,
|
||||
formData.color_scheme,
|
||||
);
|
||||
|
||||
// if dashboard has a scheme, charts should ignore individual schemes
|
||||
// thus following logic is inapplicable if a dashboard color scheme exists
|
||||
if (colorScheme) return;
|
||||
// if dashboard has a scheme, charts should ignore individual schemes
|
||||
// thus following logic is inapplicable if a dashboard color scheme exists
|
||||
if (colorScheme) return;
|
||||
|
||||
const chartColorScheme = formData.color_scheme;
|
||||
const currentChartConfig = labelsColorMapInstance.chartsLabelsMap.get(
|
||||
formData.slice_id,
|
||||
);
|
||||
const currentChartLabels = currentChartConfig?.labels || [];
|
||||
const uniqueChartLabels = currentChartLabels.filter(
|
||||
l =>
|
||||
!sharedLabelsSet.has(l) && !customLabelsColors.hasOwnProperty(l),
|
||||
);
|
||||
const chartColorScheme = formData.color_scheme;
|
||||
const currentChartConfig = labelsColorMapInstance.chartsLabelsMap.get(
|
||||
formData.slice_id,
|
||||
);
|
||||
const currentChartLabels = currentChartConfig?.labels || [];
|
||||
const uniqueChartLabels = currentChartLabels.filter(
|
||||
l => !sharedLabelsSet.has(l) && !customLabelsColors.hasOwnProperty(l),
|
||||
);
|
||||
|
||||
// Map unique labels to colors
|
||||
const uniqueChartLabelsColor = new Set(
|
||||
uniqueChartLabels.map(l => fullLabelsColors[l]).filter(Boolean),
|
||||
);
|
||||
// Map unique labels to colors
|
||||
const uniqueChartLabelsColor = new Set(
|
||||
uniqueChartLabels.map(l => fullLabelsColors[l]).filter(Boolean),
|
||||
);
|
||||
|
||||
const expectedColorsForChartScheme = new Set(
|
||||
getColorSchemeDomain(chartColorScheme),
|
||||
);
|
||||
const expectedColorsForChartScheme = new Set(
|
||||
getColorSchemeDomain(chartColorScheme),
|
||||
);
|
||||
|
||||
// Check if any unique label color is not in the expected colors set
|
||||
const shouldResetColors = [...uniqueChartLabelsColor].some(
|
||||
color => !expectedColorsForChartScheme.has(color),
|
||||
);
|
||||
// Check if any unique label color is not in the expected colors set
|
||||
const shouldResetColors = [...uniqueChartLabelsColor].some(
|
||||
color => !expectedColorsForChartScheme.has(color),
|
||||
);
|
||||
|
||||
// Only push uniqueChartLabels if they require resetting
|
||||
if (shouldResetColors) shouldReset.push(...uniqueChartLabels);
|
||||
});
|
||||
}
|
||||
|
||||
// an existing map is available, use mrge option
|
||||
// to only apply colors to newly found labels
|
||||
const shouldGoFresh = shouldReset.length > 0 ? shouldReset : false;
|
||||
const shouldMerge = !shouldGoFresh;
|
||||
// re-apply the color map first to get fresh maps accordingly
|
||||
applyColors(metadata, shouldGoFresh, shouldMerge);
|
||||
} catch (e) {
|
||||
console.error('Failed to update colors for new charts and labels:', e);
|
||||
// Only push uniqueChartLabels if they require resetting
|
||||
if (shouldResetColors) shouldReset.push(...uniqueChartLabels);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// an existing map is available, use mrge option
|
||||
// to only apply colors to newly found labels
|
||||
const shouldGoFresh = shouldReset.length > 0 ? shouldReset : false;
|
||||
const shouldMerge = !shouldGoFresh;
|
||||
// re-apply the color map first to get fresh maps accordingly
|
||||
applyColors(metadata, shouldGoFresh, shouldMerge);
|
||||
} catch (e) {
|
||||
console.error('Failed to update colors for new charts and labels:', e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ import { loadTags } from 'src/components/Tags/utils';
|
||||
import {
|
||||
applyColors,
|
||||
getColorNamespace,
|
||||
getLabelsColorMapEntries,
|
||||
getFreshLabelsColorMapEntries,
|
||||
} from 'src/utils/colorScheme';
|
||||
import getOwnerName from 'src/utils/getOwnerName';
|
||||
import Owner from 'src/types/Owner';
|
||||
@@ -369,7 +369,7 @@ const PropertiesModal = ({
|
||||
dispatch(
|
||||
setDashboardMetadata({
|
||||
...updatedDashboardMetadata,
|
||||
map_label_colors: getLabelsColorMapEntries(customLabelColors),
|
||||
map_label_colors: getFreshLabelsColorMapEntries(customLabelColors),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Select } from 'src/components';
|
||||
import { styled, t } from '@superset-ui/core';
|
||||
import { SQLEditor } from 'src/components/AsyncAceEditor';
|
||||
import sqlKeywords from 'src/SqlLab/utils/sqlKeywords';
|
||||
|
||||
import { getColumnKeywords } from 'src/explore/controlUtils/getColumnKeywords';
|
||||
import adhocMetricType from 'src/explore/components/controls/MetricControl/adhocMetricType';
|
||||
import columnType from 'src/explore/components/controls/FilterControl/columnType';
|
||||
import AdhocFilter from 'src/explore/components/controls/FilterControl/AdhocFilter';
|
||||
import { Clauses, ExpressionTypes } from '../types';
|
||||
|
||||
const propTypes = {
|
||||
adhocFilter: PropTypes.instanceOf(AdhocFilter).isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
options: PropTypes.arrayOf(
|
||||
PropTypes.oneOfType([
|
||||
columnType,
|
||||
PropTypes.shape({ saved_metric_name: PropTypes.string.isRequired }),
|
||||
adhocMetricType,
|
||||
]),
|
||||
).isRequired,
|
||||
height: PropTypes.number.isRequired,
|
||||
};
|
||||
|
||||
const StyledSelect = styled(Select)`
|
||||
${({ theme }) => `
|
||||
width: ${theme.gridUnit * 30}px;
|
||||
marginRight: ${theme.gridUnit}px;
|
||||
`}
|
||||
`;
|
||||
|
||||
export default class AdhocFilterEditPopoverSqlTabContent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.onSqlExpressionChange = this.onSqlExpressionChange.bind(this);
|
||||
this.onSqlExpressionClauseChange =
|
||||
this.onSqlExpressionClauseChange.bind(this);
|
||||
this.handleAceEditorRef = this.handleAceEditorRef.bind(this);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
if (this.aceEditorRef) {
|
||||
this.aceEditorRef.editor.resize();
|
||||
}
|
||||
}
|
||||
|
||||
onSqlExpressionClauseChange(clause) {
|
||||
this.props.onChange(
|
||||
this.props.adhocFilter.duplicateWith({
|
||||
clause,
|
||||
expressionType: ExpressionTypes.Sql,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
onSqlExpressionChange(sqlExpression) {
|
||||
this.props.onChange(
|
||||
this.props.adhocFilter.duplicateWith({
|
||||
sqlExpression,
|
||||
expressionType: ExpressionTypes.Sql,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
handleAceEditorRef(ref) {
|
||||
if (ref) {
|
||||
this.aceEditorRef = ref;
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { adhocFilter, height, options } = this.props;
|
||||
|
||||
const keywords = sqlKeywords.concat(
|
||||
getColumnKeywords(options.filter(option => option.column_name)),
|
||||
);
|
||||
const selectOptions = Object.values(Clauses).map(clause => ({
|
||||
label: clause,
|
||||
value: clause,
|
||||
}));
|
||||
|
||||
return (
|
||||
<span>
|
||||
<div className="filter-edit-clause-section">
|
||||
<div>
|
||||
<StyledSelect
|
||||
options={selectOptions}
|
||||
ariaLabel={t('Select column')}
|
||||
placeholder={t('choose WHERE or HAVING...')}
|
||||
value={adhocFilter.clause}
|
||||
onChange={this.onSqlExpressionClauseChange}
|
||||
/>
|
||||
</div>
|
||||
<span className="filter-edit-clause-info">
|
||||
<strong>WHERE</strong> {t('Filters by columns')}
|
||||
<br />
|
||||
<strong>HAVING</strong> {t('Filters by metrics')}
|
||||
</span>
|
||||
</div>
|
||||
<div css={theme => ({ marginTop: theme.gridUnit * 4 })}>
|
||||
<SQLEditor
|
||||
ref={this.handleAceEditorRef}
|
||||
keywords={keywords}
|
||||
height={`${height - 130}px`}
|
||||
onChange={this.onSqlExpressionChange}
|
||||
width="100%"
|
||||
showGutter={false}
|
||||
value={adhocFilter.sqlExpression || adhocFilter.translateToSql()}
|
||||
editorProps={{ $blockScrolling: true }}
|
||||
enableLiveAutocompletion
|
||||
className="filter-sql-editor"
|
||||
wrapEnabled
|
||||
/>
|
||||
</div>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
}
|
||||
AdhocFilterEditPopoverSqlTabContent.propTypes = propTypes;
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { useEffect, useRef, useMemo } from 'react';
|
||||
import { Select } from 'src/components';
|
||||
import { styled, t, useTheme } from '@superset-ui/core';
|
||||
import { SQLEditor } from 'src/components/AsyncAceEditor';
|
||||
import sqlKeywords from 'src/SqlLab/utils/sqlKeywords';
|
||||
import { getColumnKeywords } from 'src/explore/controlUtils/getColumnKeywords';
|
||||
import AdhocFilter from 'src/explore/components/controls/FilterControl/AdhocFilter';
|
||||
import { OptionSortType } from 'src/explore/types';
|
||||
import { ColumnMeta } from '@superset-ui/chart-controls';
|
||||
import { Clauses, ExpressionTypes } from '../types';
|
||||
|
||||
const StyledSelect = styled(Select)`
|
||||
${({ theme }) => `
|
||||
width: ${theme.gridUnit * 30}px;
|
||||
marginRight: ${theme.gridUnit}px;
|
||||
`}
|
||||
`;
|
||||
|
||||
export default function AdhocFilterEditPopoverSqlTabContent({
|
||||
adhocFilter,
|
||||
onChange,
|
||||
options,
|
||||
height,
|
||||
}: {
|
||||
adhocFilter: AdhocFilter;
|
||||
onChange: (filter: AdhocFilter) => void;
|
||||
options: OptionSortType[];
|
||||
height: number;
|
||||
}) {
|
||||
const aceEditorRef = useRef(null);
|
||||
const theme = useTheme();
|
||||
|
||||
useEffect(() => {
|
||||
// @ts-ignore
|
||||
aceEditorRef?.current?.editor.resize();
|
||||
}, [adhocFilter]);
|
||||
|
||||
const onSqlExpressionClauseChange = (clause: string) => {
|
||||
onChange(
|
||||
adhocFilter.duplicateWith({
|
||||
clause,
|
||||
expressionType: ExpressionTypes.Sql,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const onSqlExpressionChange = (sqlExpression: string) => {
|
||||
onChange(
|
||||
adhocFilter.duplicateWith({
|
||||
sqlExpression,
|
||||
expressionType: ExpressionTypes.Sql,
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
const keywords = useMemo(
|
||||
() =>
|
||||
sqlKeywords.concat(
|
||||
getColumnKeywords(
|
||||
options.filter(
|
||||
(option): option is ColumnMeta =>
|
||||
typeof option === 'object' &&
|
||||
option !== null &&
|
||||
'column_name' in option &&
|
||||
typeof option.column_name === 'string' &&
|
||||
'type' in option,
|
||||
),
|
||||
),
|
||||
),
|
||||
[sqlKeywords],
|
||||
);
|
||||
|
||||
const selectOptions = useMemo(
|
||||
() =>
|
||||
Object.values(Clauses).map(clause => ({
|
||||
label: clause,
|
||||
value: clause,
|
||||
})),
|
||||
[Clauses],
|
||||
);
|
||||
|
||||
return (
|
||||
<span>
|
||||
<div className="filter-edit-clause-section">
|
||||
<div>
|
||||
<StyledSelect
|
||||
options={selectOptions}
|
||||
ariaLabel={t('Select column')}
|
||||
placeholder={t('choose WHERE or HAVING...')}
|
||||
value={adhocFilter.clause}
|
||||
onChange={onSqlExpressionClauseChange}
|
||||
/>
|
||||
</div>
|
||||
<span className="filter-edit-clause-info">
|
||||
<strong>WHERE</strong> {t('Filters by columns')}
|
||||
<br />
|
||||
<strong>HAVING</strong> {t('Filters by metrics')}
|
||||
</span>
|
||||
</div>
|
||||
<div css={{ marginTop: theme.gridUnit * 4 }}>
|
||||
<SQLEditor
|
||||
ref={aceEditorRef}
|
||||
keywords={keywords}
|
||||
height={`${height - 130}px`}
|
||||
onChange={onSqlExpressionChange}
|
||||
width="100%"
|
||||
showGutter={false}
|
||||
value={adhocFilter.sqlExpression || adhocFilter.translateToSql()}
|
||||
editorProps={{ $blockScrolling: true }}
|
||||
enableLiveAutocompletion
|
||||
className="filter-sql-editor"
|
||||
wrapEnabled
|
||||
/>
|
||||
</div>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import {
|
||||
getCategoricalSchemeRegistry,
|
||||
getLabelsColorMap,
|
||||
} from '@superset-ui/core';
|
||||
import { intersection, omit, pick } from 'lodash';
|
||||
import { areObjectsEqual } from 'src/reduxUtils';
|
||||
|
||||
const EMPTY_ARRAY: string[] = [];
|
||||
|
||||
@@ -91,14 +93,13 @@ export const getSharedLabelsColorMapEntries = (
|
||||
* @param customLabelsColor - the custom label colors in label_colors field
|
||||
* @returns all color entries except custom label colors
|
||||
*/
|
||||
export const getLabelsColorMapEntries = (
|
||||
export const getFreshLabelsColorMapEntries = (
|
||||
customLabelsColor: Record<string, string> = {},
|
||||
): Record<string, string> => {
|
||||
const labelsColorMapInstance = getLabelsColorMap();
|
||||
const allEntries = Object.fromEntries(labelsColorMapInstance.getColorMap());
|
||||
|
||||
// custom label colors are applied and stored separetely via label_colors
|
||||
// removing all instances of custom label colors from the entries
|
||||
Object.keys(customLabelsColor).forEach(label => {
|
||||
delete allEntries[label];
|
||||
});
|
||||
@@ -106,6 +107,19 @@ export const getLabelsColorMapEntries = (
|
||||
return allEntries;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns all dynamic labels and colors (excluding custom label colors).
|
||||
*
|
||||
* @param labelsColorMap - the labels color map
|
||||
* @param customLabelsColor - the custom label colors in label_colors field
|
||||
* @returns all color entries except custom label colors
|
||||
*/
|
||||
export const getDynamicLabelsColors = (
|
||||
fullLabelsColors: Record<string, string>,
|
||||
customLabelsColor: Record<string, string> = {},
|
||||
): Record<string, string> =>
|
||||
omit(fullLabelsColors, Object.keys(customLabelsColor));
|
||||
|
||||
export const getColorSchemeDomain = (colorScheme: string) =>
|
||||
getCategoricalSchemeRegistry().get(colorScheme)?.colors || [];
|
||||
|
||||
@@ -116,20 +130,29 @@ export const getColorSchemeDomain = (colorScheme: string) =>
|
||||
* @returns true if the labels color map is the same as fresh
|
||||
*/
|
||||
export const isLabelsColorMapSynced = (
|
||||
metadata: Record<string, any>,
|
||||
storedLabelsColors: Record<string, any>,
|
||||
freshLabelsColors: Record<string, any>,
|
||||
customLabelColors: Record<string, string>,
|
||||
): boolean => {
|
||||
const storedLabelsColorMap = metadata.map_label_colors || {};
|
||||
const customLabelColors = metadata.label_colors || {};
|
||||
const freshColorMap = getLabelsColorMap().getColorMap();
|
||||
const fullFreshColorMap = {
|
||||
...Object.fromEntries(freshColorMap),
|
||||
...customLabelColors,
|
||||
};
|
||||
const freshLabelsCount = Object.keys(freshLabelsColors).length;
|
||||
|
||||
const isSynced = Object.entries(fullFreshColorMap).every(
|
||||
([label, color]) =>
|
||||
storedLabelsColorMap.hasOwnProperty(label) &&
|
||||
storedLabelsColorMap[label] === color,
|
||||
// still updating, pass
|
||||
if (!freshLabelsCount) return true;
|
||||
|
||||
const commonKeys = intersection(
|
||||
Object.keys(storedLabelsColors),
|
||||
Object.keys(freshLabelsColors),
|
||||
);
|
||||
|
||||
const comparableStoredLabelsColors = pick(storedLabelsColors, commonKeys);
|
||||
const comparableFreshLabelsColors = pick(freshLabelsColors, commonKeys);
|
||||
|
||||
const isSynced = areObjectsEqual(
|
||||
comparableStoredLabelsColors,
|
||||
comparableFreshLabelsColors,
|
||||
{
|
||||
ignoreFields: Object.keys(customLabelColors),
|
||||
},
|
||||
);
|
||||
|
||||
return isSynced;
|
||||
@@ -227,7 +250,7 @@ export const applyColors = (
|
||||
if (fresh) {
|
||||
// requires a new map all together
|
||||
applicableColorMapEntries = {
|
||||
...getLabelsColorMapEntries(customLabelsColor),
|
||||
...getFreshLabelsColorMapEntries(customLabelsColor),
|
||||
};
|
||||
}
|
||||
if (merge) {
|
||||
@@ -235,7 +258,7 @@ export const applyColors = (
|
||||
// without overriding existing ones
|
||||
applicableColorMapEntries = {
|
||||
...fullLabelsColor,
|
||||
...getLabelsColorMapEntries(customLabelsColor),
|
||||
...getFreshLabelsColorMapEntries(customLabelsColor),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,10 @@ class DashboardNativeFiltersUpdateFailedError(UpdateFailedError):
|
||||
message = _("Dashboard native filters could not be patched.")
|
||||
|
||||
|
||||
class DashboardColorsConfigUpdateFailedError(UpdateFailedError):
|
||||
message = _("Dashboard color configuration could not be updated.")
|
||||
|
||||
|
||||
class DashboardDeleteFailedError(DeleteFailedError):
|
||||
message = _("Dashboard could not be deleted.")
|
||||
|
||||
|
||||
@@ -22,9 +22,10 @@ from typing import Any, Optional
|
||||
from flask_appbuilder.models.sqla import Model
|
||||
from marshmallow import ValidationError
|
||||
|
||||
from superset import app, security_manager
|
||||
from superset import app, db, security_manager
|
||||
from superset.commands.base import BaseCommand, UpdateMixin
|
||||
from superset.commands.dashboard.exceptions import (
|
||||
DashboardColorsConfigUpdateFailedError,
|
||||
DashboardForbiddenError,
|
||||
DashboardInvalidError,
|
||||
DashboardNativeFiltersUpdateFailedError,
|
||||
@@ -202,3 +203,29 @@ class UpdateDashboardNativeFiltersCommand(UpdateDashboardCommand):
|
||||
)
|
||||
|
||||
return configuration
|
||||
|
||||
|
||||
class UpdateDashboardColorsConfigCommand(UpdateDashboardCommand):
|
||||
def __init__(
|
||||
self, model_id: int, data: dict[str, Any], mark_updated: bool = True
|
||||
) -> None:
|
||||
super().__init__(model_id, data)
|
||||
self._mark_updated = mark_updated
|
||||
|
||||
@transaction(
|
||||
on_error=partial(on_error, reraise=DashboardColorsConfigUpdateFailedError)
|
||||
)
|
||||
def run(self) -> Model:
|
||||
super().validate()
|
||||
assert self._model
|
||||
|
||||
original_changed_on = self._model.changed_on
|
||||
|
||||
DashboardDAO.update_colors_config(self._model, self._properties)
|
||||
|
||||
if not self._mark_updated:
|
||||
db.session.commit() # pylint: disable=consider-using-transaction
|
||||
# restore the original changed_on value
|
||||
self._model.changed_on = original_changed_on
|
||||
|
||||
return self._model
|
||||
|
||||
@@ -39,11 +39,11 @@ from superset.commands.database.ssh_tunnel.exceptions import (
|
||||
SSHTunnelInvalidError,
|
||||
)
|
||||
from superset.commands.database.test_connection import TestConnectionDatabaseCommand
|
||||
from superset.commands.database.utils import add_permissions
|
||||
from superset.daos.database import DatabaseDAO
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.db_engine_specs.base import GenericDBException
|
||||
from superset.exceptions import OAuth2RedirectError, SupersetErrorsException
|
||||
from superset.extensions import event_logger, security_manager
|
||||
from superset.extensions import event_logger
|
||||
from superset.models.core import Database
|
||||
from superset.utils.decorators import on_error, transaction
|
||||
|
||||
@@ -99,28 +99,7 @@ class CreateDatabaseCommand(BaseCommand):
|
||||
).run()
|
||||
|
||||
# add catalog/schema permissions
|
||||
if database.db_engine_spec.supports_catalog:
|
||||
catalogs = database.get_all_catalog_names(
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
)
|
||||
for catalog in catalogs:
|
||||
security_manager.add_permission_view_menu(
|
||||
"catalog_access",
|
||||
security_manager.get_catalog_perm(
|
||||
database.database_name, catalog
|
||||
),
|
||||
)
|
||||
else:
|
||||
# add a dummy catalog for DBs that don't support them
|
||||
catalogs = [None]
|
||||
|
||||
for catalog in catalogs:
|
||||
try:
|
||||
self.add_schema_permissions(database, catalog, ssh_tunnel)
|
||||
except GenericDBException: # pylint: disable=broad-except
|
||||
logger.warning("Error processing catalog '%s'", catalog)
|
||||
continue
|
||||
add_permissions(database, ssh_tunnel)
|
||||
except (
|
||||
SSHTunnelInvalidError,
|
||||
SSHTunnelCreateFailedError,
|
||||
@@ -148,26 +127,6 @@ class CreateDatabaseCommand(BaseCommand):
|
||||
|
||||
return database
|
||||
|
||||
def add_schema_permissions(
|
||||
self,
|
||||
database: Database,
|
||||
catalog: str,
|
||||
ssh_tunnel: Optional[SSHTunnel],
|
||||
) -> None:
|
||||
for schema in database.get_all_schema_names(
|
||||
catalog=catalog,
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
):
|
||||
security_manager.add_permission_view_menu(
|
||||
"schema_access",
|
||||
security_manager.get_schema_perm(
|
||||
database.database_name,
|
||||
catalog,
|
||||
schema,
|
||||
),
|
||||
)
|
||||
|
||||
def validate(self) -> None:
|
||||
exceptions: list[ValidationError] = []
|
||||
sqlalchemy_uri: Optional[str] = self._properties.get("sqlalchemy_uri")
|
||||
|
||||
@@ -19,6 +19,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from superset import app, db, security_manager
|
||||
from superset.commands.database.utils import add_permissions
|
||||
from superset.commands.exceptions import ImportFailedError
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.databases.utils import make_url_safe
|
||||
@@ -86,40 +87,3 @@ def import_database(
|
||||
logger.warning(ex.message)
|
||||
|
||||
return database
|
||||
|
||||
|
||||
def add_permissions(database: Database, ssh_tunnel: SSHTunnel) -> None:
|
||||
"""
|
||||
Add DAR for catalogs and schemas.
|
||||
"""
|
||||
if database.db_engine_spec.supports_catalog:
|
||||
catalogs = database.get_all_catalog_names(
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
)
|
||||
|
||||
for catalog in catalogs:
|
||||
security_manager.add_permission_view_menu(
|
||||
"catalog_access",
|
||||
security_manager.get_catalog_perm(
|
||||
database.database_name,
|
||||
catalog,
|
||||
),
|
||||
)
|
||||
else:
|
||||
catalogs = [None]
|
||||
|
||||
for catalog in catalogs:
|
||||
for schema in database.get_all_schema_names(
|
||||
catalog=catalog,
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
):
|
||||
security_manager.add_permission_view_menu(
|
||||
"schema_access",
|
||||
security_manager.get_schema_perm(
|
||||
database.database_name,
|
||||
catalog,
|
||||
schema,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from superset import security_manager
|
||||
from superset.databases.ssh_tunnel.models import SSHTunnel
|
||||
from superset.db_engine_specs.base import GenericDBException
|
||||
from superset.models.core import Database
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def add_permissions(database: Database, ssh_tunnel: SSHTunnel | None) -> None:
|
||||
"""
|
||||
Add DAR for catalogs and schemas.
|
||||
"""
|
||||
if database.db_engine_spec.supports_catalog:
|
||||
catalogs = database.get_all_catalog_names(
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
)
|
||||
|
||||
for catalog in catalogs:
|
||||
security_manager.add_permission_view_menu(
|
||||
"catalog_access",
|
||||
security_manager.get_catalog_perm(
|
||||
database.database_name,
|
||||
catalog,
|
||||
),
|
||||
)
|
||||
else:
|
||||
catalogs = [None]
|
||||
|
||||
for catalog in catalogs:
|
||||
try:
|
||||
for schema in database.get_all_schema_names(
|
||||
catalog=catalog,
|
||||
cache=False,
|
||||
ssh_tunnel=ssh_tunnel,
|
||||
):
|
||||
security_manager.add_permission_view_menu(
|
||||
"schema_access",
|
||||
security_manager.get_schema_perm(
|
||||
database.database_name,
|
||||
catalog,
|
||||
schema,
|
||||
),
|
||||
)
|
||||
except GenericDBException: # pylint: disable=broad-except
|
||||
logger.warning("Error processing catalog '%s'", catalog)
|
||||
continue
|
||||
@@ -206,7 +206,7 @@ def load_data(data_uri: str, dataset: SqlaTable, database: Database) -> None:
|
||||
|
||||
# reuse session when loading data if possible, to make import atomic
|
||||
if database.sqlalchemy_uri == current_app.config.get("SQLALCHEMY_DATABASE_URI"):
|
||||
logger.info("Loading data inside the import transaction")
|
||||
logger.debug("Loading data inside the import transaction")
|
||||
connection = db.session.connection()
|
||||
df.to_sql(
|
||||
dataset.table_name,
|
||||
@@ -219,7 +219,7 @@ def load_data(data_uri: str, dataset: SqlaTable, database: Database) -> None:
|
||||
method="multi",
|
||||
)
|
||||
else:
|
||||
logger.warning("Loading data outside the import transaction")
|
||||
logger.debug("Loading data outside the import transaction")
|
||||
with database.get_sqla_engine(
|
||||
catalog=dataset.catalog,
|
||||
schema=dataset.schema,
|
||||
|
||||
+1
-2
@@ -39,7 +39,6 @@ from importlib.resources import files
|
||||
from typing import Any, Callable, Iterator, Literal, TYPE_CHECKING, TypedDict
|
||||
|
||||
import click
|
||||
import pkg_resources
|
||||
from celery.schedules import crontab
|
||||
from flask import Blueprint
|
||||
from flask_appbuilder.security.manager import AUTH_DB
|
||||
@@ -86,7 +85,7 @@ EVENT_LOGGER = DBEventLogger()
|
||||
|
||||
SUPERSET_LOG_VIEW = True
|
||||
|
||||
BASE_DIR = pkg_resources.resource_filename("superset", "")
|
||||
BASE_DIR = str(files("superset"))
|
||||
if "SUPERSET_HOME" in os.environ:
|
||||
DATA_DIR = os.environ["SUPERSET_HOME"]
|
||||
else:
|
||||
|
||||
@@ -174,6 +174,7 @@ MODEL_API_RW_METHOD_PERMISSION_MAP = {
|
||||
"csv_metadata": "csv_upload",
|
||||
"slack_channels": "write",
|
||||
"put_filters": "write",
|
||||
"put_colors": "write",
|
||||
}
|
||||
|
||||
EXTRA_FORM_DATA_APPEND_KEYS = {
|
||||
|
||||
@@ -391,6 +391,24 @@ class DashboardDAO(BaseDAO[Dashboard]):
|
||||
|
||||
return updated_configuration
|
||||
|
||||
@classmethod
|
||||
def update_colors_config(
|
||||
cls, dashboard: Dashboard, attributes: dict[str, Any]
|
||||
) -> None:
|
||||
metadata = json.loads(dashboard.json_metadata or "{}")
|
||||
|
||||
for key in [
|
||||
"color_scheme_domain",
|
||||
"color_scheme",
|
||||
"shared_label_colors",
|
||||
"map_label_colors",
|
||||
"label_colors",
|
||||
]:
|
||||
if key in attributes:
|
||||
metadata[key] = attributes[key]
|
||||
|
||||
dashboard.json_metadata = json.dumps(metadata)
|
||||
|
||||
@staticmethod
|
||||
def add_favorite(dashboard: Dashboard) -> None:
|
||||
ids = DashboardDAO.favorited_ids([dashboard])
|
||||
|
||||
@@ -42,6 +42,7 @@ from superset.commands.dashboard.delete import (
|
||||
)
|
||||
from superset.commands.dashboard.exceptions import (
|
||||
DashboardAccessDeniedError,
|
||||
DashboardColorsConfigUpdateFailedError,
|
||||
DashboardCopyError,
|
||||
DashboardCreateFailedError,
|
||||
DashboardDeleteFailedError,
|
||||
@@ -57,6 +58,7 @@ from superset.commands.dashboard.importers.dispatcher import ImportDashboardsCom
|
||||
from superset.commands.dashboard.permalink.create import CreateDashboardPermalinkCommand
|
||||
from superset.commands.dashboard.unfave import DelFavoriteDashboardCommand
|
||||
from superset.commands.dashboard.update import (
|
||||
UpdateDashboardColorsConfigCommand,
|
||||
UpdateDashboardCommand,
|
||||
UpdateDashboardNativeFiltersCommand,
|
||||
)
|
||||
@@ -81,6 +83,7 @@ from superset.dashboards.permalink.types import DashboardPermalinkState
|
||||
from superset.dashboards.schemas import (
|
||||
CacheScreenshotSchema,
|
||||
DashboardCacheScreenshotResponseSchema,
|
||||
DashboardColorsConfigUpdateSchema,
|
||||
DashboardCopySchema,
|
||||
DashboardDatasetSchema,
|
||||
DashboardGetResponseSchema,
|
||||
@@ -108,6 +111,7 @@ from superset.tasks.thumbnails import (
|
||||
)
|
||||
from superset.tasks.utils import get_current_user
|
||||
from superset.utils import json
|
||||
from superset.utils.core import parse_boolean_string
|
||||
from superset.utils.pdf import build_pdf_from_screenshots
|
||||
from superset.utils.screenshots import (
|
||||
DashboardScreenshot,
|
||||
@@ -187,6 +191,7 @@ class DashboardRestApi(BaseSupersetModelRestApi):
|
||||
"cache_dashboard_screenshot",
|
||||
"screenshot",
|
||||
"put_filters",
|
||||
"put_colors",
|
||||
}
|
||||
resource_name = "dashboard"
|
||||
allow_browser_login = True
|
||||
@@ -275,6 +280,7 @@ class DashboardRestApi(BaseSupersetModelRestApi):
|
||||
add_model_schema = DashboardPostSchema()
|
||||
edit_model_schema = DashboardPutSchema()
|
||||
update_filters_model_schema = DashboardNativeFiltersConfigUpdateSchema()
|
||||
update_colors_model_schema = DashboardColorsConfigUpdateSchema()
|
||||
chart_entity_response_schema = ChartEntityResponseSchema()
|
||||
dashboard_get_response_schema = DashboardGetResponseSchema()
|
||||
dashboard_dataset_schema = DashboardDatasetSchema()
|
||||
@@ -767,6 +773,88 @@ class DashboardRestApi(BaseSupersetModelRestApi):
|
||||
response = self.response_422(message=str(ex))
|
||||
return response
|
||||
|
||||
@expose("/<pk>/colors", methods=("PUT",))
|
||||
@protect()
|
||||
@safe
|
||||
@statsd_metrics
|
||||
@event_logger.log_this_with_context(
|
||||
action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.put_colors",
|
||||
log_to_statsd=False,
|
||||
)
|
||||
@requires_json
|
||||
def put_colors(self, pk: int) -> Response:
|
||||
"""
|
||||
Modify colors configuration for a dashboard.
|
||||
---
|
||||
put:
|
||||
summary: Update colors configuration for a dashboard.
|
||||
parameters:
|
||||
- in: path
|
||||
schema:
|
||||
type: integer
|
||||
name: pk
|
||||
- in: query
|
||||
name: mark_updated
|
||||
schema:
|
||||
type: boolean
|
||||
description: Whether to update the dashboard changed_on field
|
||||
requestBody:
|
||||
description: Colors configuration
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/DashboardColorsConfigUpdateSchema'
|
||||
responses:
|
||||
200:
|
||||
description: Dashboard colors updated
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
result:
|
||||
type: array
|
||||
400:
|
||||
$ref: '#/components/responses/400'
|
||||
401:
|
||||
$ref: '#/components/responses/401'
|
||||
403:
|
||||
$ref: '#/components/responses/403'
|
||||
404:
|
||||
$ref: '#/components/responses/404'
|
||||
422:
|
||||
$ref: '#/components/responses/422'
|
||||
500:
|
||||
$ref: '#/components/responses/500'
|
||||
"""
|
||||
try:
|
||||
item = self.update_colors_model_schema.load(request.json, partial=True)
|
||||
except ValidationError as error:
|
||||
return self.response_400(message=error.messages)
|
||||
|
||||
try:
|
||||
mark_updated = parse_boolean_string(
|
||||
request.args.get("mark_updated", "true")
|
||||
)
|
||||
UpdateDashboardColorsConfigCommand(pk, item, mark_updated).run()
|
||||
response = self.response(200)
|
||||
except DashboardNotFoundError:
|
||||
response = self.response_404()
|
||||
except DashboardForbiddenError:
|
||||
response = self.response_403()
|
||||
except DashboardInvalidError as ex:
|
||||
return self.response_422(message=ex.normalized_messages())
|
||||
except DashboardColorsConfigUpdateFailedError as ex:
|
||||
logger.error(
|
||||
"Error changing color configuration for dashboard %s: %s",
|
||||
self.__class__.__name__,
|
||||
str(ex),
|
||||
exc_info=True,
|
||||
)
|
||||
response = self.response_422(message=str(ex))
|
||||
return response
|
||||
|
||||
@expose("/<pk>", methods=("DELETE",))
|
||||
@protect()
|
||||
@safe
|
||||
@@ -1174,6 +1262,11 @@ class DashboardRestApi(BaseSupersetModelRestApi):
|
||||
schema:
|
||||
type: string
|
||||
name: digest
|
||||
- in: query
|
||||
name: download_format
|
||||
schema:
|
||||
type: string
|
||||
enum: [png, pdf]
|
||||
responses:
|
||||
200:
|
||||
description: Dashboard thumbnail image
|
||||
|
||||
@@ -428,6 +428,15 @@ class DashboardNativeFiltersConfigUpdateSchema(BaseDashboardSchema):
|
||||
reordered = fields.List(fields.String(), allow_none=False)
|
||||
|
||||
|
||||
class DashboardColorsConfigUpdateSchema(BaseDashboardSchema):
|
||||
color_namespace = fields.String(allow_none=True)
|
||||
color_scheme = fields.String(allow_none=True)
|
||||
map_label_colors = fields.Dict(allow_none=False)
|
||||
shared_label_colors = SharedLabelsColorsField()
|
||||
label_colors = fields.Dict(allow_none=False)
|
||||
color_scheme_domain = fields.List(fields.String(), allow_none=False)
|
||||
|
||||
|
||||
class DashboardScreenshotPostSchema(Schema):
|
||||
dataMask = fields.Dict(
|
||||
keys=fields.Str(),
|
||||
|
||||
@@ -1632,10 +1632,10 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
)
|
||||
@requires_form_data
|
||||
def csv_metadata(self) -> Response:
|
||||
"""Upload an CSV file and returns file metadata.
|
||||
"""Upload a CSV file and returns file metadata.
|
||||
---
|
||||
post:
|
||||
summary: Upload an CSV file and returns file metadata
|
||||
summary: Upload a CSV file and returns file metadata
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
import textwrap
|
||||
from typing import Union
|
||||
|
||||
@@ -40,6 +41,8 @@ from .helpers import (
|
||||
update_slice_ids,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def gen_filter(
|
||||
subject: str, comparator: str, operator: str = "=="
|
||||
@@ -83,8 +86,7 @@ def load_data(tbl_name: str, database: Database, sample: bool = False) -> None:
|
||||
method="multi",
|
||||
index=False,
|
||||
)
|
||||
print("Done loading table!")
|
||||
print("-" * 80)
|
||||
logging.debug("Done loading table!")
|
||||
|
||||
|
||||
def load_birth_names(
|
||||
@@ -104,7 +106,7 @@ def load_birth_names(
|
||||
table = get_table_connector_registry()
|
||||
obj = db.session.query(table).filter_by(table_name=tbl_name, schema=schema).first()
|
||||
if not obj:
|
||||
print(f"Creating table [{tbl_name}] reference")
|
||||
logging.debug(f"Creating table [{tbl_name}] reference")
|
||||
obj = table(table_name=tbl_name, schema=schema)
|
||||
db.session.add(obj)
|
||||
|
||||
@@ -196,7 +198,7 @@ def create_slices(tbl: SqlaTable) -> tuple[list[Slice], list[Slice]]:
|
||||
"datasource_type": DatasourceType.TABLE,
|
||||
}
|
||||
|
||||
print("Creating some slices")
|
||||
logger.debug("Creating some slices")
|
||||
slices = [
|
||||
Slice(
|
||||
**slice_kwargs,
|
||||
@@ -561,7 +563,7 @@ def create_slices(tbl: SqlaTable) -> tuple[list[Slice], list[Slice]]:
|
||||
|
||||
|
||||
def create_dashboard(slices: list[Slice]) -> Dashboard:
|
||||
print("Creating a dashboard")
|
||||
logger.debug("Creating a dashboard")
|
||||
dash = db.session.query(Dashboard).filter_by(slug="births").first()
|
||||
if not dash:
|
||||
dash = Dashboard()
|
||||
|
||||
@@ -505,7 +505,9 @@ def upgrade_schema_perms(
|
||||
.filter_by(name=current_perm)
|
||||
.one_or_none()
|
||||
):
|
||||
existing_pvm.name = new_perm
|
||||
# check that new_perm does not exist
|
||||
if not session.query(ViewMenu).filter_by(name=new_perm).one_or_none():
|
||||
existing_pvm.name = new_perm
|
||||
elif new_perm:
|
||||
# new schema discovered, need to create a new permission
|
||||
perms[new_perm] = ("schema_access",)
|
||||
@@ -683,7 +685,9 @@ def downgrade_schema_perms(
|
||||
None,
|
||||
schema,
|
||||
)
|
||||
pvms_to_rename.append((pvm, new_name))
|
||||
# check to see if the new name already exists
|
||||
if not session.query(ViewMenu).filter_by(name=new_name).one_or_none():
|
||||
pvms_to_rename.append((pvm, new_name))
|
||||
else:
|
||||
# non-default catalog, delete schema perm
|
||||
pvms_to_delete.append(pvm)
|
||||
|
||||
@@ -19,10 +19,8 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects.sqlite.base import SQLiteDialect # noqa: E402
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.utils.core import generic_find_fk_constraint_name
|
||||
|
||||
|
||||
@@ -73,23 +71,3 @@ def redefine(
|
||||
ondelete=on_delete,
|
||||
onupdate=on_update,
|
||||
)
|
||||
|
||||
|
||||
def drop_fks_for_table(table_name: str) -> None:
|
||||
"""
|
||||
Drop all foreign key constraints for a table if it exist and the database
|
||||
is not sqlite.
|
||||
|
||||
:param table_name: The table name to drop foreign key constraints for
|
||||
"""
|
||||
connection = op.get_bind()
|
||||
inspector = Inspector.from_engine(connection)
|
||||
|
||||
if isinstance(connection.dialect, SQLiteDialect):
|
||||
return # sqlite doesn't like constraints
|
||||
|
||||
if has_table(table_name):
|
||||
foreign_keys = inspector.get_foreign_keys(table_name)
|
||||
|
||||
for fk in foreign_keys:
|
||||
op.drop_constraint(fk["name"], table_name, type_="foreignkey")
|
||||
|
||||
@@ -21,17 +21,25 @@ from collections.abc import Iterator
|
||||
from typing import Any, Callable, Optional, Union
|
||||
from uuid import uuid4
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy import Column, inspect
|
||||
from sqlalchemy.dialects.mysql.base import MySQLDialect
|
||||
from sqlalchemy.dialects.postgresql.base import PGDialect
|
||||
from sqlalchemy.dialects.sqlite.base import SQLiteDialect # noqa: E402
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlalchemy.exc import NoSuchTableError
|
||||
from sqlalchemy.orm import Query, Session
|
||||
from sqlalchemy.sql.schema import SchemaItem
|
||||
|
||||
from superset.utils import json
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
GREEN = "\033[32m"
|
||||
RESET = "\033[0m"
|
||||
YELLOW = "\033[33m"
|
||||
RED = "\033[31m"
|
||||
LRED = "\033[91m"
|
||||
|
||||
logger = logging.getLogger("alembic")
|
||||
|
||||
DEFAULT_BATCH_SIZE = int(os.environ.get("BATCH_SIZE", 1000))
|
||||
|
||||
@@ -185,15 +193,208 @@ def has_table(table_name: str) -> bool:
|
||||
return table_exists
|
||||
|
||||
|
||||
def add_column_if_not_exists(table_name: str, column: sa.Column) -> None:
|
||||
def drop_fks_for_table(table_name: str) -> None:
|
||||
"""
|
||||
Adds a column to a table if it does not already exist.
|
||||
Drop all foreign key constraints for a table if it exist and the database
|
||||
is not sqlite.
|
||||
|
||||
:param table_name: Name of the table.
|
||||
:param column: SQLAlchemy Column object.
|
||||
:param table_name: The table name to drop foreign key constraints for
|
||||
"""
|
||||
if not table_has_column(table_name, column.name):
|
||||
print(f"Adding column '{column.name}' to table '{table_name}'.\n")
|
||||
op.add_column(table_name, column)
|
||||
else:
|
||||
print(f"Column '{column.name}' already exists in table '{table_name}'.\n")
|
||||
connection = op.get_bind()
|
||||
inspector = Inspector.from_engine(connection)
|
||||
|
||||
if isinstance(connection.dialect, SQLiteDialect):
|
||||
return # sqlite doesn't like constraints
|
||||
|
||||
if has_table(table_name):
|
||||
foreign_keys = inspector.get_foreign_keys(table_name)
|
||||
for fk in foreign_keys:
|
||||
logger.info(
|
||||
f"Dropping foreign key {GREEN}{fk['name']}{RESET} from table {GREEN}{table_name}{RESET}..."
|
||||
)
|
||||
op.drop_constraint(fk["name"], table_name, type_="foreignkey")
|
||||
|
||||
|
||||
def create_table(table_name: str, *columns: SchemaItem) -> None:
|
||||
"""
|
||||
Creates a database table with the specified name and columns.
|
||||
|
||||
This function checks if a table with the given name already exists in the database.
|
||||
If the table already exists, it logs an informational.
|
||||
Otherwise, it proceeds to create a new table using the provided name and schema columns.
|
||||
|
||||
:param table_name: The name of the table to be created.
|
||||
:param columns: A variable number of arguments representing the schema just like when calling alembic's method create_table()
|
||||
"""
|
||||
|
||||
if has_table(table_name=table_name):
|
||||
logger.info(f"Table {LRED}{table_name}{RESET} already exists. Skipping...")
|
||||
return
|
||||
|
||||
logger.info(f"Creating table {GREEN}{table_name}{RESET}...")
|
||||
op.create_table(table_name, *columns)
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} created.")
|
||||
|
||||
|
||||
def drop_table(table_name: str) -> None:
|
||||
"""
|
||||
Drops a database table with the specified name.
|
||||
|
||||
This function checks if a table with the given name exists in the database.
|
||||
If the table does not exist, it logs an informational message and skips the dropping process.
|
||||
If the table exists, it first attempts to drop all foreign key constraints associated with the table
|
||||
(handled by `drop_fks_for_table`) and then proceeds to drop the table.
|
||||
|
||||
:param table_name: The name of the table to be dropped.
|
||||
"""
|
||||
|
||||
if not has_table(table_name=table_name):
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} doesn't exist. Skipping...")
|
||||
return
|
||||
|
||||
logger.info(f"Dropping table {GREEN}{table_name}{RESET}...")
|
||||
drop_fks_for_table(table_name)
|
||||
op.drop_table(table_name=table_name)
|
||||
logger.info(f"Table {GREEN}{table_name}{RESET} dropped.")
|
||||
|
||||
|
||||
def batch_operation(
|
||||
callable: Callable[[int, int], None], count: int, batch_size: int
|
||||
) -> None:
|
||||
"""
|
||||
Executes an operation by dividing a task into smaller batches and tracking progress.
|
||||
|
||||
This function is designed to process a large number of items in smaller batches. It takes a callable
|
||||
that performs the operation on each batch. The function logs the progress of the operation as it processes
|
||||
through the batches.
|
||||
|
||||
If count is set to 0 or lower, it logs an informational message and skips the batch process.
|
||||
|
||||
:param callable: A callable function that takes two integer arguments:
|
||||
the start index and the end index of the current batch.
|
||||
:param count: The total number of items to process.
|
||||
:param batch_size: The number of items to process in each batch.
|
||||
"""
|
||||
if count <= 0:
|
||||
logger.info(
|
||||
f"No records to process in batch {LRED}(count <= 0){RESET} for callable {LRED}other_callable_example{RESET}. Skipping..."
|
||||
)
|
||||
return
|
||||
for offset in range(0, count, batch_size):
|
||||
percentage = (offset / count) * 100 if count else 0
|
||||
logger.info(f"Progress: {offset:,}/{count:,} ({percentage:.2f}%)")
|
||||
callable(offset, min(offset + batch_size, count))
|
||||
|
||||
logger.info(f"Progress: {count:,}/{count:,} (100%)")
|
||||
logger.info(
|
||||
f"End: {GREEN}{callable.__name__}{RESET} batch operation {GREEN}succesfully{RESET} executed."
|
||||
)
|
||||
|
||||
|
||||
def add_columns(table_name: str, *columns: Column) -> None:
|
||||
"""
|
||||
Adds new columns to an existing database table.
|
||||
|
||||
If a column already exists, it logs an informational message and skips the adding process.
|
||||
Otherwise, it proceeds to add the new column to the table.
|
||||
|
||||
The operation is performed using Alembic's batch_alter_table.
|
||||
|
||||
:param table_name: The name of the table to which the columns will be added.
|
||||
:param columns: A list of SQLAlchemy Column objects that define the name, type, and other attributes of the columns to be added.
|
||||
"""
|
||||
|
||||
cols_to_add = []
|
||||
for col in columns:
|
||||
if table_has_column(table_name=table_name, column_name=col.name):
|
||||
logger.info(
|
||||
f"Column {LRED}{col.name}{RESET} already present on table {LRED}{table_name}{RESET}. Skipping..."
|
||||
)
|
||||
else:
|
||||
cols_to_add.append(col)
|
||||
|
||||
with op.batch_alter_table(table_name) as batch_op:
|
||||
for col in cols_to_add:
|
||||
logger.info(
|
||||
f"Adding column {GREEN}{col.name}{RESET} to table {GREEN}{table_name}{RESET}..."
|
||||
)
|
||||
batch_op.add_column(col)
|
||||
|
||||
|
||||
def drop_columns(table_name: str, *columns: str) -> None:
|
||||
"""
|
||||
Drops specified columns from an existing database table.
|
||||
|
||||
If a column does not exist, it logs an informational message and skips the dropping process.
|
||||
Otherwise, it proceeds to remove the column from the table.
|
||||
|
||||
The operation is performed using Alembic's batch_alter_table.
|
||||
|
||||
:param table_name: The name of the table from which the columns will be removed.
|
||||
:param columns: A list of column names to be dropped.
|
||||
"""
|
||||
|
||||
cols_to_drop = []
|
||||
for col in columns:
|
||||
if not table_has_column(table_name=table_name, column_name=col):
|
||||
logger.info(
|
||||
f"Column {LRED}{col}{RESET} is not present on table {LRED}{table_name}{RESET}. Skipping..."
|
||||
)
|
||||
else:
|
||||
cols_to_drop.append(col)
|
||||
|
||||
with op.batch_alter_table(table_name) as batch_op:
|
||||
for col in cols_to_drop:
|
||||
logger.info(
|
||||
f"Dropping column {GREEN}{col}{RESET} from table {GREEN}{table_name}{RESET}..."
|
||||
)
|
||||
batch_op.drop_column(col)
|
||||
|
||||
|
||||
def create_index(table_name: str, index_name: str, *columns: str) -> None:
|
||||
"""
|
||||
Creates an index on specified columns of an existing database table.
|
||||
|
||||
If the index already exists, it logs an informational message and skips the creation process.
|
||||
Otherwise, it proceeds to create a new index with the specified name on the given columns of the table.
|
||||
|
||||
:param table_name: The name of the table on which the index will be created.
|
||||
:param index_name: The name of the index to be created.
|
||||
:param columns: A list column names where the index will be created
|
||||
"""
|
||||
|
||||
if table_has_index(table=table_name, index=index_name):
|
||||
logger.info(
|
||||
f"Table {LRED}{table_name}{RESET} already has index {LRED}{index_name}{RESET}. Skipping..."
|
||||
)
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Creating index {GREEN}{index_name}{RESET} on table {GREEN}{table_name}{RESET}"
|
||||
)
|
||||
|
||||
op.create_index(table_name=table_name, index_name=index_name, columns=columns)
|
||||
|
||||
|
||||
def drop_index(table_name: str, index_name: str) -> None:
|
||||
"""
|
||||
Drops an index from an existing database table.
|
||||
|
||||
If the index does not exists, it logs an informational message and skips the dropping process.
|
||||
Otherwise, it proceeds with the removal operation.
|
||||
|
||||
:param table_name: The name of the table from which the index will be dropped.
|
||||
:param index_name: The name of the index to be dropped.
|
||||
"""
|
||||
|
||||
if not table_has_index(table=table_name, index=index_name):
|
||||
logger.info(
|
||||
f"Table {LRED}{table_name}{RESET} doesn't have index {LRED}{index_name}{RESET}. Skipping..."
|
||||
)
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Dropping index {GREEN}{index_name}{RESET} from table {GREEN}{table_name}{RESET}..."
|
||||
)
|
||||
|
||||
op.drop_index(table_name=table_name, index_name=index_name)
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import sqlalchemy as sa # noqa: E402
|
||||
from alembic import op # noqa: E402
|
||||
from sqlalchemy_utils import EncryptedType # noqa: E402
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table # noqa: E402
|
||||
from superset.migrations.shared.utils import drop_fks_for_table # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
@@ -22,9 +22,8 @@ Create Date: 2024-04-01 22:44:40.386543
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.utils import add_column_if_not_exists
|
||||
from superset.migrations.shared.utils import add_columns, drop_columns
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "c22cb5c2e546"
|
||||
@@ -32,11 +31,11 @@ down_revision = "678eefb4ab44"
|
||||
|
||||
|
||||
def upgrade():
|
||||
add_column_if_not_exists(
|
||||
add_columns(
|
||||
"user_attribute",
|
||||
sa.Column("avatar_url", sa.String(length=100), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column("user_attribute", "avatar_url")
|
||||
drop_columns("user_attribute", "avatar_url")
|
||||
|
||||
@@ -23,9 +23,8 @@ Create Date: 2024-04-11 15:41:34.663989
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.utils import add_column_if_not_exists
|
||||
from superset.migrations.shared.utils import add_columns, drop_columns
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "5f57af97bc3f"
|
||||
@@ -36,12 +35,9 @@ tables = ["tables", "query", "saved_query", "tab_state", "table_schema"]
|
||||
|
||||
def upgrade():
|
||||
for table in tables:
|
||||
add_column_if_not_exists(
|
||||
table,
|
||||
sa.Column("catalog", sa.String(length=256), nullable=True),
|
||||
)
|
||||
add_columns(table, sa.Column("catalog", sa.String(length=256), nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
for table in reversed(tables):
|
||||
op.drop_column(table, "catalog")
|
||||
drop_columns(table, "catalog")
|
||||
|
||||
+7
-10
@@ -23,13 +23,12 @@ Create Date: 2024-05-01 10:52:31.458433
|
||||
"""
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.catalogs import (
|
||||
downgrade_catalog_perms,
|
||||
upgrade_catalog_perms,
|
||||
)
|
||||
from superset.migrations.shared.utils import add_column_if_not_exists
|
||||
from superset.migrations.shared.utils import add_columns, drop_columns
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "58d051681a3b"
|
||||
@@ -37,18 +36,16 @@ down_revision = "4a33124c18ad"
|
||||
|
||||
|
||||
def upgrade():
|
||||
add_column_if_not_exists(
|
||||
"tables",
|
||||
sa.Column("catalog_perm", sa.String(length=1000), nullable=True),
|
||||
add_columns(
|
||||
"tables", sa.Column("catalog_perm", sa.String(length=1000), nullable=True)
|
||||
)
|
||||
add_column_if_not_exists(
|
||||
"slices",
|
||||
sa.Column("catalog_perm", sa.String(length=1000), nullable=True),
|
||||
add_columns(
|
||||
"slices", sa.Column("catalog_perm", sa.String(length=1000), nullable=True)
|
||||
)
|
||||
upgrade_catalog_perms(engines={"postgresql"})
|
||||
|
||||
|
||||
def downgrade():
|
||||
downgrade_catalog_perms(engines={"postgresql"})
|
||||
op.drop_column("slices", "catalog_perm")
|
||||
op.drop_column("tables", "catalog_perm")
|
||||
drop_columns("slices", "catalog_perm")
|
||||
drop_columns("tables", "catalog_perm")
|
||||
|
||||
+1
-2
@@ -25,8 +25,7 @@ Create Date: 2024-05-24 11:31:57.115586
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "02f4f7811799"
|
||||
|
||||
+1
-2
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:17:23.273168
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "39549add7bfc"
|
||||
|
||||
+1
-2
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:23:28.768963
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "38f4144e8558"
|
||||
|
||||
+1
-2
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:27:11.589886
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "e53fd48cc078"
|
||||
|
||||
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:29:33.135672
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "a6b32d2d07b1"
|
||||
|
||||
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:31:31.478017
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "007a1abffe7e"
|
||||
|
||||
@@ -25,8 +25,7 @@ Create Date: 2024-08-13 15:33:14.551012
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
from superset.migrations.shared.constraints import drop_fks_for_table
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.migrations.shared.utils import drop_fks_for_table, has_table
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "48cbb571fa3a"
|
||||
|
||||
@@ -329,13 +329,13 @@ class ImportExportMixin:
|
||||
is_new_obj = True
|
||||
# Create new DB object
|
||||
obj = cls(**dict_rep)
|
||||
logger.info("Importing new %s %s", obj.__tablename__, str(obj))
|
||||
logger.debug("Importing new %s %s", obj.__tablename__, str(obj))
|
||||
if cls.export_parent and parent:
|
||||
setattr(obj, cls.export_parent, parent)
|
||||
db.session.add(obj)
|
||||
else:
|
||||
is_new_obj = False
|
||||
logger.info("Updating %s %s", obj.__tablename__, str(obj))
|
||||
logger.debug("Updating %s %s", obj.__tablename__, str(obj))
|
||||
# Update columns
|
||||
for k, v in dict_rep.items():
|
||||
setattr(obj, k, v)
|
||||
|
||||
+8
-23
@@ -47,6 +47,7 @@ from superset.tags.schemas import (
|
||||
openapi_spec_methods_override,
|
||||
TaggedObjectEntityResponseSchema,
|
||||
TagGetResponseSchema,
|
||||
TagPostBulkResponseSchema,
|
||||
TagPostBulkSchema,
|
||||
TagPostSchema,
|
||||
TagPutSchema,
|
||||
@@ -132,6 +133,8 @@ class TagRestApi(BaseSupersetModelRestApi):
|
||||
openapi_spec_component_schemas = (
|
||||
TagGetResponseSchema,
|
||||
TaggedObjectEntityResponseSchema,
|
||||
TagPostBulkResponseSchema,
|
||||
TagPostBulkSchema,
|
||||
)
|
||||
apispec_parameter_schemas = {
|
||||
"delete_tags_schema": delete_tags_schema,
|
||||
@@ -211,40 +214,21 @@ class TagRestApi(BaseSupersetModelRestApi):
|
||||
"""Bulk create tags and tagged objects
|
||||
---
|
||||
post:
|
||||
summary: Get all objects associated with a tag
|
||||
parameters:
|
||||
- in: path
|
||||
schema:
|
||||
type: integer
|
||||
name: tag_id
|
||||
summary: Bulk create tags and tagged objects
|
||||
requestBody:
|
||||
description: Tag schema
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
tags:
|
||||
description: list of tag names to add to object
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
objects_to_tag:
|
||||
description: list of object names to add to object
|
||||
type: array
|
||||
items:
|
||||
type: array
|
||||
$ref: '#/components/schemas/TagPostBulkSchema'
|
||||
responses:
|
||||
200:
|
||||
description: Tag added to favorites
|
||||
description: Bulk created tags and tagged objects
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
result:
|
||||
type: object
|
||||
$ref: '#/components/schemas/TagPostBulkResponseSchema'
|
||||
302:
|
||||
description: Redirects to the current digest
|
||||
400:
|
||||
@@ -267,6 +251,7 @@ class TagRestApi(BaseSupersetModelRestApi):
|
||||
tagged_item: dict[str, Any] = self.add_model_schema.load(
|
||||
{
|
||||
"name": tag.get("name"),
|
||||
"description": tag.get("description"),
|
||||
"objects_to_tag": tag.get("objects_to_tag"),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -53,21 +53,41 @@ class TaggedObjectEntityResponseSchema(Schema):
|
||||
changed_on = fields.DateTime()
|
||||
created_by = fields.Nested(UserSchema(exclude=["username"]))
|
||||
creator = fields.String()
|
||||
tags = fields.List(fields.Nested(TagGetResponseSchema))
|
||||
owners = fields.List(fields.Nested(UserSchema))
|
||||
tags = fields.List(fields.Nested(TagGetResponseSchema()))
|
||||
owners = fields.List(fields.Nested(UserSchema()))
|
||||
|
||||
|
||||
objects_to_tag_field = fields.List(
|
||||
fields.Tuple(
|
||||
(
|
||||
fields.String(metadata={"description": "type of resource"}),
|
||||
fields.Int(validate=Range(min=1), metadata={"description": "resource id"}),
|
||||
),
|
||||
),
|
||||
metadata={
|
||||
"description": "Objects to tag",
|
||||
},
|
||||
required=False,
|
||||
)
|
||||
|
||||
|
||||
class TagObjectSchema(Schema):
|
||||
name = fields.String(validate=Length(min=1))
|
||||
description = fields.String(required=False, allow_none=True)
|
||||
objects_to_tag = fields.List(
|
||||
fields.Tuple((fields.String(), fields.Int(validate=Range(min=1)))),
|
||||
required=False,
|
||||
)
|
||||
objects_to_tag = objects_to_tag_field
|
||||
|
||||
|
||||
class TagPostBulkSchema(Schema):
|
||||
tags = fields.List(fields.Nested(TagObjectSchema))
|
||||
tags = fields.List(fields.Nested(TagObjectSchema()))
|
||||
|
||||
|
||||
class TagPostBulkResponseObjectSchema(Schema):
|
||||
objects_tagged = objects_to_tag_field
|
||||
objects_skipped = objects_to_tag_field
|
||||
|
||||
|
||||
class TagPostBulkResponseSchema(Schema):
|
||||
result = fields.Nested(TagPostBulkResponseObjectSchema())
|
||||
|
||||
|
||||
class TagPostSchema(TagObjectSchema):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3197,3 +3197,114 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
|
||||
|
||||
response = self._cache_screenshot(dashboard.id)
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_put_dashboard_colors(self):
|
||||
"""
|
||||
Dashboard API: Test updating dashboard colors
|
||||
"""
|
||||
self.login(ADMIN_USERNAME)
|
||||
dashboard = Dashboard.get("world_health")
|
||||
|
||||
colors = {
|
||||
"label_colors": {"Sales": "#FF0000", "Profit": "#00FF00"},
|
||||
"shared_label_colors": ["#0000FF", "#FFFF00"],
|
||||
"map_label_colors": {"Revenue": "#FFFFFF"},
|
||||
"color_scheme": "d3Category10",
|
||||
}
|
||||
|
||||
uri = f"api/v1/dashboard/{dashboard.id}/colors"
|
||||
rv = self.client.put(uri, json=colors)
|
||||
assert rv.status_code == 200
|
||||
|
||||
updated_dashboard = db.session.query(Dashboard).get(dashboard.id)
|
||||
updated_label_colors = json.loads(updated_dashboard.json_metadata).get(
|
||||
"label_colors"
|
||||
)
|
||||
updated_shared_label_colors = json.loads(updated_dashboard.json_metadata).get(
|
||||
"shared_label_colors"
|
||||
)
|
||||
updated_map_label_colors = json.loads(updated_dashboard.json_metadata).get(
|
||||
"map_label_colors"
|
||||
)
|
||||
updated_color_scheme = json.loads(updated_dashboard.json_metadata).get(
|
||||
"color_scheme"
|
||||
)
|
||||
|
||||
assert updated_label_colors == colors["label_colors"]
|
||||
assert updated_shared_label_colors == colors["shared_label_colors"]
|
||||
assert updated_map_label_colors == colors["map_label_colors"]
|
||||
assert updated_color_scheme == colors["color_scheme"]
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_put_dashboard_colors_no_mark_updated(self):
|
||||
"""
|
||||
Dashboard API: Test updating dashboard colors without marking the dashboard as updated
|
||||
"""
|
||||
self.login(ADMIN_USERNAME)
|
||||
dashboard = Dashboard.get("world_health")
|
||||
|
||||
colors = {"color_scheme": "d3Category10"}
|
||||
|
||||
previous_changed_on = dashboard.changed_on
|
||||
uri = f"api/v1/dashboard/{dashboard.id}/colors?mark_updated=false"
|
||||
rv = self.client.put(uri, json=colors)
|
||||
assert rv.status_code == 200
|
||||
|
||||
updated_dashboard = db.session.query(Dashboard).get(dashboard.id)
|
||||
updated_color_scheme = json.loads(updated_dashboard.json_metadata).get(
|
||||
"color_scheme"
|
||||
)
|
||||
|
||||
assert updated_color_scheme == colors["color_scheme"]
|
||||
assert updated_dashboard.changed_on == previous_changed_on
|
||||
|
||||
def test_put_dashboard_colors_not_found(self):
|
||||
"""
|
||||
Dashboard API: Test updating colors for dashboard that does not exist
|
||||
"""
|
||||
self.login(ADMIN_USERNAME)
|
||||
|
||||
colors = {"label_colors": {"Sales": "#FF0000"}}
|
||||
|
||||
invalid_id = self.get_nonexistent_numeric_id(Dashboard)
|
||||
uri = f"api/v1/dashboard/{invalid_id}/colors"
|
||||
rv = self.client.put(uri, json=colors)
|
||||
assert rv.status_code == 404
|
||||
|
||||
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
|
||||
def test_put_dashboard_colors_invalid(self):
|
||||
"""
|
||||
Dashboard API: Test updating dashboard colors with invalid color format
|
||||
"""
|
||||
self.login(ADMIN_USERNAME)
|
||||
dashboard = Dashboard.get("world_health")
|
||||
|
||||
colors = {"test_invalid_prop": {"Sales": "invalid"}}
|
||||
|
||||
uri = f"api/v1/dashboard/{dashboard.id}/colors"
|
||||
rv = self.client.put(uri, json=colors)
|
||||
assert rv.status_code == 400
|
||||
|
||||
def test_put_dashboard_colors_not_authorized(self):
|
||||
"""
|
||||
Dashboard API: Test updating colors without authorization
|
||||
"""
|
||||
with self.create_app().app_context():
|
||||
admin = security_manager.find_user("admin")
|
||||
dashboard = self.insert_dashboard("title", None, [admin.id])
|
||||
|
||||
assert dashboard.id is not None
|
||||
|
||||
colors = {"label_colors": {"Sales": "#FF0000"}}
|
||||
|
||||
self.login(GAMMA_USERNAME)
|
||||
uri = f"api/v1/dashboard/{dashboard.id}/colors"
|
||||
rv = self.client.put(uri, json=colors)
|
||||
assert rv.status_code == 403
|
||||
|
||||
yield dashboard
|
||||
|
||||
# Cleanup
|
||||
db.session.delete(dashboard)
|
||||
db.session.commit()
|
||||
|
||||
@@ -23,7 +23,6 @@ from pytest_mock import MockerFixture
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
from superset import db
|
||||
from superset.commands.database.importers.v1.utils import add_permissions
|
||||
from superset.commands.exceptions import ImportFailedError
|
||||
from superset.utils import json
|
||||
|
||||
@@ -216,30 +215,3 @@ def test_import_database_with_user_impersonation(
|
||||
|
||||
database = import_database(config)
|
||||
assert database.impersonate_user is True
|
||||
|
||||
|
||||
def test_add_permissions(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
Test adding permissions to a database when it's imported.
|
||||
"""
|
||||
database = mocker.MagicMock()
|
||||
database.database_name = "my_db"
|
||||
database.db_engine_spec.supports_catalog = True
|
||||
database.get_all_catalog_names.return_value = ["catalog1", "catalog2"]
|
||||
database.get_all_schema_names.side_effect = [["schema1"], ["schema2"]]
|
||||
ssh_tunnel = mocker.MagicMock()
|
||||
add_permission_view_menu = mocker.patch(
|
||||
"superset.commands.database.importers.v1.utils.security_manager."
|
||||
"add_permission_view_menu"
|
||||
)
|
||||
|
||||
add_permissions(database, ssh_tunnel)
|
||||
|
||||
add_permission_view_menu.assert_has_calls(
|
||||
[
|
||||
mocker.call("catalog_access", "[my_db].[catalog1]"),
|
||||
mocker.call("catalog_access", "[my_db].[catalog2]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog1].[schema1]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog2].[schema2]"),
|
||||
]
|
||||
)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from superset.commands.database.utils import add_permissions
|
||||
|
||||
|
||||
def test_add_permissions(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
Test adding permissions to a database when it's created.
|
||||
"""
|
||||
database = mocker.MagicMock()
|
||||
database.database_name = "my_db"
|
||||
database.db_engine_spec.supports_catalog = True
|
||||
database.get_all_catalog_names.return_value = ["catalog1", "catalog2"]
|
||||
database.get_all_schema_names.side_effect = [["schema1"], ["schema2"]]
|
||||
ssh_tunnel = mocker.MagicMock()
|
||||
add_permission_view_menu = mocker.patch(
|
||||
"superset.commands.database.importers.v1.utils.security_manager."
|
||||
"add_permission_view_menu"
|
||||
)
|
||||
|
||||
add_permissions(database, ssh_tunnel)
|
||||
|
||||
add_permission_view_menu.assert_has_calls(
|
||||
[
|
||||
mocker.call("catalog_access", "[my_db].[catalog1]"),
|
||||
mocker.call("catalog_access", "[my_db].[catalog2]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog1].[schema1]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog2].[schema2]"),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def test_add_permissions_handle_failures(mocker: MockerFixture) -> None:
|
||||
"""
|
||||
Test adding permissions to a database when it's created in case
|
||||
the request to get all schemas for one fo the catalogs fail.
|
||||
"""
|
||||
database = mocker.MagicMock()
|
||||
database.database_name = "my_db"
|
||||
database.db_engine_spec.supports_catalog = True
|
||||
database.get_all_catalog_names.return_value = ["catalog1", "catalog2", "catalog3"]
|
||||
database.get_all_schema_names.side_effect = [["schema1"], Exception, ["schema3"]]
|
||||
ssh_tunnel = mocker.MagicMock()
|
||||
add_permission_view_menu = mocker.patch(
|
||||
"superset.commands.database.importers.v1.utils.security_manager."
|
||||
"add_permission_view_menu"
|
||||
)
|
||||
|
||||
add_permissions(database, ssh_tunnel)
|
||||
|
||||
add_permission_view_menu.assert_has_calls(
|
||||
[
|
||||
mocker.call("catalog_access", "[my_db].[catalog1]"),
|
||||
mocker.call("catalog_access", "[my_db].[catalog2]"),
|
||||
mocker.call("catalog_access", "[my_db].[catalog3]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog1].[schema1]"),
|
||||
mocker.call("schema_access", "[my_db].[catalog3].[schema3]"),
|
||||
]
|
||||
)
|
||||
Reference in New Issue
Block a user