Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(file_factory): convert tool file correctly. #11167

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions api/factories/file_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def build_from_mapping(
tenant_id: str,
config: FileUploadConfig | None = None,
) -> File:
config = config or FileUploadConfig()

transfer_method = FileTransferMethod.value_of(mapping.get("transfer_method"))

build_functions: dict[FileTransferMethod, Callable] = {
Expand All @@ -72,7 +70,7 @@ def build_from_mapping(
transfer_method=transfer_method,
)

if not _is_file_valid_with_config(
if config and not _is_file_valid_with_config(
input_file_type=mapping.get("type", FileType.CUSTOM),
file_extension=file.extension,
file_transfer_method=file.transfer_method,
Expand Down Expand Up @@ -127,7 +125,7 @@ def _build_from_local_file(
if row is None:
raise ValueError("Invalid upload file")

file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension="." + row.extension, mime_type=row.mime_type)

return File(
Expand Down Expand Up @@ -157,7 +155,7 @@ def _build_from_remote_url(
mime_type, filename, file_size = _get_remote_file_info(url)
extension = mimetypes.guess_extension(mime_type) or "." + filename.split(".")[-1] if "." in filename else ".bin"

file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension=extension, mime_type=mime_type)

return File(
Expand Down Expand Up @@ -208,7 +206,7 @@ def _build_from_tool_file(
raise ValueError(f"ToolFile {mapping.get('tool_file_id')} not found")

extension = "." + tool_file.file_key.split(".")[-1] if "." in tool_file.file_key else ".bin"
file_type = FileType(mapping.get("type"))
file_type = FileType(mapping.get("type", "custom"))
file_type = _standardize_file_type(file_type, extension=extension, mime_type=tool_file.mimetype)

return File(
Expand Down