From b9cd330d99eaa7d407de516fb4c780c30169ee9f Mon Sep 17 00:00:00 2001 From: Linxiushen <1787979356@qq.com> Date: Mon, 21 Sep 2026 21:06:28 +0800 Subject: [PATCH] fix(antdx): FileCard / FileCard.List.Item crash when `src` is a file dict without `url` Both constructors handle a `src` dict that has a `path` but no `url` by serving the local file, but the branch referenced `self.item`, an attribute that does not exist on either class, so the constructor raised AttributeError instead. The next line then unconditionally overwrote `self.src` with the raw dict, so the branch could never take effect even if the lookup had worked. Read the path from `src` itself and merge the served file info back into `src` before the assignment, which is what the code was written to do. Behaviour for string, url-bearing dict and empty `src` values is unchanged. --- .changeset/fix-file-card-src-dict.md | 5 +++++ .../modelscope_studio/components/antdx/file_card/__init__.py | 2 +- .../components/antdx/file_card/list/item/__init__.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-file-card-src-dict.md diff --git a/.changeset/fix-file-card-src-dict.md b/.changeset/fix-file-card-src-dict.md new file mode 100644 index 00000000..d7895dc1 --- /dev/null +++ b/.changeset/fix-file-card-src-dict.md @@ -0,0 +1,5 @@ +--- +'modelscope_studio': patch +--- + +fix: `antdx.FileCard` and `antdx.FileCard.List.Item` raise `AttributeError` when `src` is a file dict without a `url` diff --git a/backend/modelscope_studio/components/antdx/file_card/__init__.py b/backend/modelscope_studio/components/antdx/file_card/__init__.py index cf7466ea..02fea45b 100644 --- a/backend/modelscope_studio/components/antdx/file_card/__init__.py +++ b/backend/modelscope_studio/components/antdx/file_card/__init__.py @@ -88,7 +88,7 @@ def __init__( self.src = self.serve_static_file(src) elif isinstance(src, dict): if not src.get("url", None) and src.get("path", None): - self.src = {**src, **self.serve_static_file(self.item["path"])} + src = {**src, **self.serve_static_file(src["path"])} self.src = src FRONTEND_DIR = resolve_frontend_dir('file-card', type="antdx") diff --git a/backend/modelscope_studio/components/antdx/file_card/list/item/__init__.py b/backend/modelscope_studio/components/antdx/file_card/list/item/__init__.py index 6de8bdb3..1423d940 100644 --- a/backend/modelscope_studio/components/antdx/file_card/list/item/__init__.py +++ b/backend/modelscope_studio/components/antdx/file_card/list/item/__init__.py @@ -85,7 +85,7 @@ def __init__( self.src = self.serve_static_file(src) elif isinstance(src, dict): if not src.get("url", None) and src.get("path", None): - self.src = {**src, **self.serve_static_file(self.item["path"])} + src = {**src, **self.serve_static_file(src["path"])} self.src = src FRONTEND_DIR = resolve_frontend_dir('file-card', ['list', 'item'],