chore(backend): replace insecure `shortid` usage for native filter migration with native `uuid` Python implementation (#32235)
Signed-off-by: hainenber <dotronghai96@gmail.com>
This commit is contained in:
parent
af3589fe91
commit
21348c418a
|
|
@ -87,7 +87,6 @@ dependencies = [
|
||||||
"redis>=4.6.0, <5.0",
|
"redis>=4.6.0, <5.0",
|
||||||
"selenium>=4.14.0, <5.0",
|
"selenium>=4.14.0, <5.0",
|
||||||
"shillelagh[gsheetsapi]>=1.2.18, <2.0",
|
"shillelagh[gsheetsapi]>=1.2.18, <2.0",
|
||||||
"shortid",
|
|
||||||
"sshtunnel>=0.4.0, <0.5",
|
"sshtunnel>=0.4.0, <0.5",
|
||||||
"simplejson>=3.15.0",
|
"simplejson>=3.15.0",
|
||||||
"slack_sdk>=3.19.0, <4",
|
"slack_sdk>=3.19.0, <4",
|
||||||
|
|
|
||||||
|
|
@ -329,8 +329,6 @@ selenium==4.27.1
|
||||||
# via apache-superset (pyproject.toml)
|
# via apache-superset (pyproject.toml)
|
||||||
shillelagh==1.2.18
|
shillelagh==1.2.18
|
||||||
# via apache-superset (pyproject.toml)
|
# via apache-superset (pyproject.toml)
|
||||||
shortid==0.1.2
|
|
||||||
# via apache-superset (pyproject.toml)
|
|
||||||
simplejson==3.19.3
|
simplejson==3.19.3
|
||||||
# via apache-superset (pyproject.toml)
|
# via apache-superset (pyproject.toml)
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
|
|
|
||||||
|
|
@ -738,10 +738,6 @@ shillelagh==1.2.18
|
||||||
# via
|
# via
|
||||||
# -c requirements/base.txt
|
# -c requirements/base.txt
|
||||||
# apache-superset
|
# apache-superset
|
||||||
shortid==0.1.2
|
|
||||||
# via
|
|
||||||
# -c requirements/base.txt
|
|
||||||
# apache-superset
|
|
||||||
simplejson==3.19.3
|
simplejson==3.19.3
|
||||||
# via
|
# via
|
||||||
# -c requirements/base.txt
|
# -c requirements/base.txt
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,10 @@ from collections import defaultdict
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from shortid import ShortId
|
|
||||||
|
|
||||||
from superset.models.dashboard import Dashboard
|
from superset.models.dashboard import Dashboard
|
||||||
from superset.models.slice import Slice
|
from superset.models.slice import Slice
|
||||||
from superset.utils import json
|
from superset.utils import json
|
||||||
|
from superset.utils.core import shortid
|
||||||
from superset.utils.dashboard_filter_scopes_converter import convert_filter_scopes
|
from superset.utils.dashboard_filter_scopes_converter import convert_filter_scopes
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,7 +48,6 @@ def convert_filter_scopes_to_native_filters( # pylint: disable=invalid-name,too
|
||||||
:see: convert_filter_scopes
|
:see: convert_filter_scopes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
shortid = ShortId()
|
|
||||||
default_filters = json.loads(json_metadata.get("default_filters") or "{}")
|
default_filters = json.loads(json_metadata.get("default_filters") or "{}")
|
||||||
filter_scopes = json_metadata.get("filter_scopes", {})
|
filter_scopes = json_metadata.get("filter_scopes", {})
|
||||||
filter_box_ids = {filter_box.id for filter_box in filter_boxes}
|
filter_box_ids = {filter_box.id for filter_box in filter_boxes}
|
||||||
|
|
@ -76,16 +74,27 @@ def convert_filter_scopes_to_native_filters( # pylint: disable=invalid-name,too
|
||||||
}
|
}
|
||||||
|
|
||||||
# Construct the native filters.
|
# Construct the native filters.
|
||||||
|
unique_short_ids = set()
|
||||||
for filter_box in filter_boxes:
|
for filter_box in filter_boxes:
|
||||||
key = str(filter_box.id)
|
key = str(filter_box.id)
|
||||||
params = json.loads(filter_box.params or "{}")
|
params = json.loads(filter_box.params or "{}")
|
||||||
|
|
||||||
for field, filter_scope in filter_scope_by_key_and_field[key].items():
|
for field, filter_scope in filter_scope_by_key_and_field[key].items():
|
||||||
default = default_filters.get(key, {}).get(field)
|
default = default_filters.get(key, {}).get(field)
|
||||||
|
short_id = f"{shortid()}"[:9]
|
||||||
|
|
||||||
|
# Ensure uniqueness due to UUIDv4 truncation increasing
|
||||||
|
# collision chance to infinitesimally small amount.
|
||||||
|
while True:
|
||||||
|
if short_id not in unique_short_ids:
|
||||||
|
unique_short_ids.add(short_id)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
short_id = f"{shortid()}"[:9]
|
||||||
|
|
||||||
fltr: dict[str, Any] = {
|
fltr: dict[str, Any] = {
|
||||||
"cascadeParentIds": [],
|
"cascadeParentIds": [],
|
||||||
"id": f"NATIVE_FILTER-{shortid.generate()}",
|
"id": f"NATIVE_FILTER-{short_id}",
|
||||||
"scope": {
|
"scope": {
|
||||||
"rootPath": filter_scope["scope"],
|
"rootPath": filter_scope["scope"],
|
||||||
"excluded": [
|
"excluded": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue