Skip to content

fix(utils): keep resource rows without a parent in the tree #1479 - #1481

Open
borealisalastor-byte wants to merge 1 commit into
dataease:mainfrom
borealisalastor-byte:fix/dashboard-tree-root
Open

borealisalastor-byte wants to merge 1 commit into
dataease:mainfrom
borealisalastor-byte:fix/dashboard-tree-root

Conversation

@borealisalastor-byte

Copy link
Copy Markdown
Contributor

apps/dashboard/crud/dashboard_service.py::list_resource 用 build_tree_generic(nodes, root_pid="root") 组装看板列表,而 build_tree_generic 只把 pid == root_pid 的行当作根节点。BaseDashboard.pid 的默认值是空字符串,get_create_base_info 直接 CoreDashboard(**dashboard.model_dump()) 落库;历史数据里也可能有 pid 为 NULL 的行。这些行的 pid 既不等于 "root" 也不在 node_dict 中,于是从列表中消失(接口 200,但看不到自己创建的看板)。

同一函数里,pid 指向自身的行会被追加为自己的子节点,递归序列化该结果会一直展开下去。

改动

common/utils/tree_utils.py:

  • 把空 pid("" / None)与 root_pid 同等视为根节点;
  • 自引用行保持可见,但不再成为自己的子节点;
  • 父节点不存在的行维持原行为(不进入树),避免把脏数据挂到任意节点。

验证(cd backend 后执行)

  • pytest -q tests/test_resource_tree_roots.py → 修复前 2 failed / 2 passed,修复后 4 passed
    • 覆盖:pid 为 "root" / "" / None 均为根;三级父子挂载正确;自引用行可见且无子节点;未知父节点的行仍不进入树
  • pytest -q tests --continue-on-collection-errors → 无新增失败;本机唯一失败仍是 test_model_discovery.py::test_real_route_permission_and_safe_error(缺少 sqlbot_xpack,环境限制)

Fixes #1479

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 看板列表按 root_pid=root 建树,pid 为空或历史 NULL 的行会从列表消失

1 participant