fix(antdx): FileCard / FileCard.List.Item crash when src is a file dict without url - #128
Merged
Merged
Conversation
…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 detectedLatest commit: b9cd330 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Collaborator
|
@Linxiushen Thanks for this fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
antdx.FileCardandantdx.FileCard.List.Itemacceptsrceither as a string or as a file dict (the frontend type isstring | FileData). The dict branch in both constructors reads:self.itemdoes not exist on either class or on their base classes, so passing a dict with apathbut nourlraises at construction time:That shape is the natural one for files the app produced or received locally.
pro.Chatbot.postprocessemits exactly{'path': ..., 'url': None, ...}for a local attachment, for example. Even if the lookup had worked, the following unconditionalself.src = srcoverwrote 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
srcitself and merge the served file info back intosrcbefore the existing assignment, which is what the code was written to do.I did not drop the branch and pass the raw dict through: a bare
pathis served via/gradio_api/file=only afterserve_static_filehas 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
testsdirectory is git-ignored), so I verified with a local script against the real components under gradio 6.28:FileDatawith a/gradio_api/file=...url after it. The string, url-bearing dict and{path: None}cases are byte-identical before and after.docs/components/antdx/file_card/demos/basic.pybuilds with the same number of blocks before and after.A changeset is included (
patchformodelscope_studio).This fix was developed with AI assistance (Claude); the change was reviewed and verified locally before submission.