Fix File helper extension handling#4531
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
Preserve explicit suffixes when building data-backed File resource URIs, while keeping the inferred-extension fallback for names without a suffix. Closes PrefectHQ#4530 Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
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.
Description
Preserve explicit extensions when data-backed
Filehelpers build their resource URI.Closes #4530
Before this change,
File(data=bx, format=pdf, name=report.pdf)producedfile:///report.pdf.pdf. The fix keeps caller-provided names with an existing suffix unchanged, while preserving the existing fallback that appends the inferred subtype for names without a suffix.The affected call chain is a tool returning
File->_convert_to_content()->File.to_resource_content(). Path-backed files, data-backed files without a custom name, and the existing text/blob resource-content split are unchanged.Validation:
uv syncPYTHONUTF8=1 uv run --frozen pytest tests/utilities/test_types.py -q(82 passed)PYTHONUTF8=1 uv run pytest tests/tools/tool/test_content.py tests/tools/tool/test_tool.py tests/server/tasks/test_task_return_types.py tests/server/providers/local_provider_tools/test_local_provider_tools.py -q(132 passed)PYTHONUTF8=1 uv run --frozen ruff format --check fastmcp_slim/fastmcp/utilities/types.py tests/utilities/test_types.pyPYTHONUTF8=1 uv run --frozen ruff check fastmcp_slim/fastmcp/utilities/types.py tests/utilities/test_types.pygit diff --checkLocal full-suite notes:
PYTHONUTF8=1 uv run prek --refresh run --all-filesreached the hooks successfully after refreshing cache, butty checkfails on Windows with existingfcntl.flock/LOCK_EX/LOCK_UNunresolved-attribute diagnostics intests/utilities/json_schema_type/test_real_world_schemas.py.PYTHONUTF8=1 uv run pytest -n autofails in this Windows environment on unrelated environment/platform paths, including missingnpxfor conformance, symlink privilegeWinError 1314, and xdist worker crashes.Contribution type
Checklist
uv run prek run --all-filesand all checks pass