fix: resolve benchmark prompt assets without asserting concrete asset types#625
fix: resolve benchmark prompt assets without asserting concrete asset types#625RapidPoseidon wants to merge 1 commit into
Conversation
… types RapidataBenchmark.__instantiate_prompts asserted that each prompt's prompt_asset.actual_instance was a FileAssetModel and then indexed metadata["sourceUrl"]. Neither holds for the current API response: the prompts endpoint returns an IAssetModel oneOf wrapper whose actual_instance is an IAssetModel* variant (file/multi/text/null), and only URL-registered assets carry a "sourceUrl" metadata entry. File-uploaded prompts only have originalFilename/imageDimension, so the assert raised AssertionError (and the index would otherwise KeyError) on any benchmark with file assets. Because identifiers/prompts/prompt_assets/tags all lazily call this method, and add_model/add_prompts read self.identifiers, the crash blocked the whole participant-adding flow. Resolve the source URL defensively (mirroring RapidataFlowItem._extract_asset_key): navigate actual_instance -> metadata -> "sourceUrl" with getattr/.get and fall back to None when no URL is present, rather than asserting concrete types. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-Authored-By: karl <karl@rapidata.ai>
Code ReviewOverviewThis PR fixes a real crash in Correctness
Code QualityMinor style concern — docstring length on a private method. The # IAssetModel is a oneOf wrapper; only URL-registered assets carry a "sourceUrl"
# metadata entry — navigate defensively rather than asserting concrete types.That captures the essential constraint without repeating the full type hierarchy already visible in the surrounding code. TYPE_CHECKING Import
ToolingPR description confirms:
Potential Follow-ups (not blocking)
SummaryClean, well-scoped fix. The defensive |
Problem
RapidataBenchmark.identifiers(andprompts/prompt_assets/tags) crashes on any benchmark whose prompts have file assets — which blocksadd_modelandadd_prompts, since both readself.identifiersinternally.__instantiate_promptsdid:Neither assumption holds against the current API response:
prompt.prompt_assetis anIAssetModeloneOf wrapper; its.actual_instanceis anIAssetModel*variant (IAssetModelFileAssetModel/…MultiAssetModel/…TextAssetModel/…NullAssetModel) — never the bareFileAssetModel. →AssertionError.metadataisDict[str, IMetadataModel]and only carries a"sourceUrl"entry for URL-registered assets. File-uploaded prompts only haveoriginalFilename/imageDimension, sometadata["sourceUrl"]wouldKeyError.IMetadataModelSourceUrlMetadataModel, not the bareSourceUrlMetadataModel, so the second assert is wrong too.Reproduced live against a real file-asset benchmark (499 prompts):
benchmark.identifiersraisedAssertionErrorbefore this change.Fix
Resolve the source URL defensively instead of asserting concrete types, mirroring the existing pattern in
RapidataFlowItem._extract_asset_key():prompt_assetsnow yields the source URL when present, elseNonefor file-uploaded assets that have no public URL in the response — the old code could never have returned a URL for those anyway; it crashed.Verification
identifiers,prompts,prompt_assets,tagsall populate (499 each) with no exception;add_model's identifier-membership check passes.uv run black src/rapidata/rapidata_client→ unchanged.uv run pyright src/rapidata/rapidata_client/benchmark/rapidata_benchmark.py→ 0 errors, 0 warnings.Notes
release_and_publish.yml).IAssetModel*wrapper + missingsourceUrl) would be worth adding once test infra exists.Image-Editing-Benchmarks(RapidataAI/Image-Editing-Benchmarks#6), which currently ships a consumer-side cache-injection workaround that can be removed once this releases.🔗 Session: ${POSEIDON_SESSION_URL:-$HOSTNAME}
🤖 Generated with Claude Code