Repository navigation
Description
Bug description
When DATASET_FOLDERS is enabled, validate_folders() in superset/commands/dataset/update.py (lines 941–994) performs a breadth-first traversal over the folder tree to verify UUID uniqueness, detect cycles, and enforce that folder names are unique among siblings while allowing identical folder names in different parent folders.
However, during BFS child traversal (lines 992–994), path is mutated in-place and the same list reference is shared across every sibling under a parent:
# superset/commands/dataset/update.py (lines 955-994)
queue: list[tuple[FolderSchema, list[UUID]]] = [(folder, []) for folder in folders]
seen_uuids = set()
seen_fqns = set() # fully qualified folder names
while queue:
obj, path = queue.pop(0)
uuid, name = obj["uuid"], obj.get("name")
if uuid in path:
raise ValidationError(f"Cycle detected: {uuid} appears in its ancestry")
...
# folders can have duplicate name as long as they're not siblings
if name:
fqn = tuple(path + [name])
if name and fqn in seen_fqns:
raise ValidationError(f"Duplicate folder name: {name}")
seen_fqns.add(fqn)
...
# traverse children
if children := obj.get("children"):
path.append(uuid)
queue.extend((folder, path) for folder in children)Whenever a parent folder has multiple children and an earlier child itself has children (such as columns, metrics, or subfolders), path.append(uuid) mutates the shared path list seen by all remaining siblings (and their descendants) in queue. This breaks both sibling duplicate detection and non-sibling allowance:
-
False negative (allows duplicate sibling folder names):
- Put two sibling folders both named
"Sales"inside a parent folder"Root", where the first"Sales"folder has any child (for example, a subfolder, metric, or column). - Expected:
ValidationError("Duplicate folder name: Sales")(rejected as422onPUT /api/v1/dataset/<pk>). - Actual: Validation passes. After visiting the first
"Sales"folder,path.append(sales_1_uuid)mutates the shared list from[root_uuid]to[root_uuid, sales_1_uuid]. When the second"Sales"sibling is popped, itsfqnis computed as(root_uuid, sales_1_uuid, "Sales"), which does not match(root_uuid, "Sales")inseen_fqns.
- Put two sibling folders both named
-
False positive (rejects valid non-sibling folders with the same name):
- Put two non-sibling folders named
"Overview"inside"Root": one nested under"Root" -> "GroupA" -> "Overview", and one directly under"Root" -> "Overview"(after"GroupA"in"Root"'schildrenlist). - Expected: Validation passes because
"Overview"under"GroupA"and"Overview"under"Root"are not siblings. - Actual: Validation raises
ValidationError("Duplicate folder name: Overview")."GroupA"appendsgroup_a_uuidto the sharedpathlist ([root_uuid, group_a_uuid]). Both"Root" -> "Overview"(dequeued next in BFS) and"Root" -> "GroupA" -> "Overview"read that same mutatedpath, producing the identicalfqn(root_uuid, group_a_uuid, "Overview").
- Put two non-sibling folders named
-
Corrupted ancestry tracking (
if uuid in path):- Because
pathaccumulates UUIDs from earlier siblings that had children rather than holding only true ancestors,pathno longer represents a node's ancestry chain.
- Because
Steps to reproduce
Enable DATASET_FOLDERS = True and send a PUT /api/v1/dataset/<pk> payload (or call validate_folders(FolderSchema(many=True).load(folders), valid_uuids) directly) with either folder structure:
Case 1 — Duplicate sibling folders erroneously accepted:
[
{
"uuid": "11111111-1111-1111-1111-111111111111",
"type": "folder",
"name": "Root",
"children": [
{
"uuid": "22222222-2222-2222-2222-222222222222",
"type": "folder",
"name": "Sales",
"children": [
{
"uuid": "33333333-3333-3333-3333-333333333333",
"type": "folder",
"name": "Sub",
"children": []
}
]
},
{
"uuid": "44444444-4444-4444-4444-444444444444",
"type": "folder",
"name": "Sales",
"children": []
}
]
}
]Case 2 — Valid non-sibling folders erroneously rejected (Duplicate folder name: Overview):
[
{
"uuid": "11111111-1111-1111-1111-111111111111",
"type": "folder",
"name": "Root",
"children": [
{
"uuid": "22222222-2222-2222-2222-222222222222",
"type": "folder",
"name": "GroupA",
"children": [
{
"uuid": "33333333-3333-3333-3333-333333333333",
"type": "folder",
"name": "Overview",
"children": []
}
]
},
{
"uuid": "44444444-4444-4444-4444-444444444444",
"type": "folder",
"name": "Overview",
"children": []
}
]
}
]Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.11
Node version
16
Browser
Chrome
Additional context
Additional context
- Code pointers:
superset/commands/dataset/update.pylines 451–473 (UpdateDatasetCommand._validate_semantics) and lines 941–994 (validate_folders).superset/datasets/schemas.pylines 231–258 (FolderSchema).superset/config.pyline 793 ("DATASET_FOLDERS": False, enabled in dev atdocker/pythonpath_dev/superset_config.pyline 118).
- Why existing tests missed this:
test_validate_folders_duplicate_name_not_siblings(tests/unit_tests/commands/dataset/update_test.pylines 1280–1324) andtest_validate_folders_duplicate_name_siblings(lines 1327–1373) both place the duplicate folder names in separate top-level root items (folders = [root1, root2]), which receive independent[]lists on line 955 rather than sharing a parent'spathlist.
- Proposed fix:
- Avoid mutating
pathin-place (for example, use immutabletuple[UUID, ...]paths withcollections.deque, or create a new pathnew_path = [*path, uuid]when enqueuing children):queue: deque[tuple[FolderSchema, tuple[UUID, ...]]] = deque( (folder, ()) for folder in folders ) ... while queue: obj, path = queue.popleft() ... if name: fqn = (*path, name) if fqn in seen_fqns: raise ValidationError(f"Duplicate folder name: {name}") seen_fqns.add(fqn) ... if children := obj.get("children"): child_path = (*path, uuid) queue.extend((folder, child_path) for folder in children)
- Add regression unit tests in
tests/unit_tests/commands/dataset/update_test.pycovering both nested sibling duplicates (with a populated first sibling) and nested non-sibling folders at different depths sharing a name under the same ancestor.
- Avoid mutating
Checklist
- I have searched Superset docs and Slack and didn't find a solution to my problem.
- I have searched the GitHub issue tracker and didn't find a similar bug report.
- I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
Activity