Skip to content

Commit b9cd330

Browse files
committed
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.
1 parent 2ff63d5 commit b9cd330

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'modelscope_studio': patch
3+
---
4+
5+
fix: `antdx.FileCard` and `antdx.FileCard.List.Item` raise `AttributeError` when `src` is a file dict without a `url`

‎backend/modelscope_studio/components/antdx/file_card/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(
8888
self.src = self.serve_static_file(src)
8989
elif isinstance(src, dict):
9090
if not src.get("url", None) and src.get("path", None):
91-
self.src = {**src, **self.serve_static_file(self.item["path"])}
91+
src = {**src, **self.serve_static_file(src["path"])}
9292
self.src = src
9393

9494
FRONTEND_DIR = resolve_frontend_dir('file-card', type="antdx")

‎backend/modelscope_studio/components/antdx/file_card/list/item/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
self.src = self.serve_static_file(src)
8686
elif isinstance(src, dict):
8787
if not src.get("url", None) and src.get("path", None):
88-
self.src = {**src, **self.serve_static_file(self.item["path"])}
88+
src = {**src, **self.serve_static_file(src["path"])}
8989
self.src = src
9090

9191
FRONTEND_DIR = resolve_frontend_dir('file-card', ['list', 'item'],

0 commit comments

Comments
 (0)