18
18
from textwrap import dedent
19
19
from typing import Any
20
20
21
- from shortid import ShortId
22
-
23
21
from superset .models .dashboard import Dashboard
24
22
from superset .models .slice import Slice
25
23
from superset .utils import json
24
+ from superset .utils .core import shortid
26
25
from superset .utils .dashboard_filter_scopes_converter import convert_filter_scopes
27
26
28
27
@@ -49,7 +48,6 @@ def convert_filter_scopes_to_native_filters( # pylint: disable=invalid-name,too
49
48
:see: convert_filter_scopes
50
49
"""
51
50
52
- shortid = ShortId ()
53
51
default_filters = json .loads (json_metadata .get ("default_filters" ) or "{}" )
54
52
filter_scopes = json_metadata .get ("filter_scopes" , {})
55
53
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
76
74
}
77
75
78
76
# Construct the native filters.
77
+ unique_short_ids = set ()
79
78
for filter_box in filter_boxes :
80
79
key = str (filter_box .id )
81
80
params = json .loads (filter_box .params or "{}" )
82
81
83
82
for field , filter_scope in filter_scope_by_key_and_field [key ].items ():
84
83
default = default_filters .get (key , {}).get (field )
84
+ short_id = f"{ shortid ()} " [:9 ]
85
+
86
+ # Ensure uniqueness due to UUIDv4 truncation increasing
87
+ # collision chance to infinitesimally small amount.
88
+ while True :
89
+ if short_id not in unique_short_ids :
90
+ unique_short_ids .add (short_id )
91
+ break
92
+ else :
93
+ short_id = f"{ shortid ()} " [:9 ]
85
94
86
95
fltr : dict [str , Any ] = {
87
96
"cascadeParentIds" : [],
88
- "id" : f"NATIVE_FILTER-{ shortid . generate () } " ,
97
+ "id" : f"NATIVE_FILTER-{ short_id } " ,
89
98
"scope" : {
90
99
"rootPath" : filter_scope ["scope" ],
91
100
"excluded" : [
0 commit comments