Skip to content

fix(antdx): FileCard / FileCard.List.Item crash when src is a file dict without url - #128

Merged
Col0ring merged 1 commit into
modelscope:mainfrom
Linxiushen:fix-file-card-src-dict
Sep 22, 2026
Merged

Col0ring merged 1 commit into
modelscope:mainfrom
Linxiushen:fix-file-card-src-dict

Conversation

@Linxiushen

Copy link
Copy Markdown
Contributor

Problem

antdx.FileCard and antdx.FileCard.List.Item accept src either as a string or as a file dict (the frontend type is string | FileData). The dict branch in both constructors reads:

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"])}
    self.src = src

self.item does not exist on either class or on their base classes, so passing a dict with a path but no url raises at construction time:

AttributeError: 'AntdXFileCard' object has no attribute 'item'

That shape is the natural one for files the app produced or received locally. pro.Chatbot.postprocess emits exactly {'path': ..., 'url': None, ...} for a local attachment, for example. Even if the lookup had worked, the following unconditional self.src = src overwrote the served value, so the branch could never take effect.

Reachability, stated plainly: the bundled demo passes an http URL string and is not affected. The crash needs a caller to pass a local-file dict, which is a documented input shape.

Fix

One line in each file: read the path from src itself and merge the served file info back into src before the existing assignment, which is what the code was written to do.

src = {**src, **self.serve_static_file(src["path"])}

I did not drop the branch and pass the raw dict through: a bare path is served via /gradio_api/file= only after serve_static_file has registered it, otherwise the frontend gets a 403 and shows a card that silently fails to open.

Verification

The repo has no tracked tests (the tests directory is git-ignored), so I verified with a local script against the real components under gradio 6.28:

  • 8 checks: the two local-file dict cases fail with the AttributeError before the fix and produce a normal FileData with a /gradio_api/file=... url after it. The string, url-bearing dict and {path: None} cases are byte-identical before and after.
  • The bundled docs/components/antdx/file_card/demos/basic.py builds with the same number of blocks before and after.

A changeset is included (patch for modelscope_studio).


This fix was developed with AI assistance (Claude); the change was reviewed and verified locally before submission.

…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-bot

changeset-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b9cd330

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
modelscope_studio Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Col0ring
Col0ring merged commit c061f04 into modelscope:main Sep 22, 2026
1 check passed
@Col0ring

Copy link
Copy Markdown
Collaborator

@Linxiushen Thanks for this fix.

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.

2 participants