fix: send the content_type partition_via_api accepts - #4489
Open
linhongyu510 wants to merge 1 commit into
Open
linhongyu510 wants to merge 1 commit into
linhongyu510 wants to merge 1 commit into
Conversation
`content_type` has been the second positional parameter of `partition_via_api()` since the helper was introduced in Unstructured-IO#518, and the docstring describes it as "a string defining the file content in MIME type". It is never read: both `shared.Files(...)` call sites pass only `content` and `file_name`, so the value is silently discarded and the server falls back to sniffing the file name. `shared.Files` does have a `content_type` field, so nothing was missing on the SDK side -- only the hand-off. Populate it when the caller supplies a value: partition_via_api(filename=..., content_type="text/markdown") # before: files.content_type is None # after: files.content_type == "text/markdown" The field is left unset when no `content_type` is given, so the SDK keeps inferring the type from the file name exactly as before. The parameter is not moved, so existing positional calls are unaffected.
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
content_typehas been the second positional parameter ofpartition_via_api()since the helper was introduced in #518, and the docstring describes it as:It is never read. Both construction sites pass only
contentandfile_name:so the value is silently discarded and the server falls back to sniffing the file name — exactly the situation the parameter exists to override (an extensionless upload, a file whose extension lies about its type, or a stream where only the caller knows the format).
Measured on
main(3376cc96) by capturing the request handed to the SDK:This is not an SDK limitation:
shared.Fileshas acontent_typefield (['content', 'file_name', 'content_type']). Only the hand-off was missing.Fix
Populate the field when the caller supplies a value.
When no
content_typeis given the field is left unset rather than passed asNone, so the SDK keeps inferring the type from the file name exactly as before. The parameter is not moved, so existing positional calls bind unchanged.Tests
test_partition_via_api_sends_an_explicit_content_type_for_a_filenametest_partition_via_api_sends_an_explicit_content_type_for_a_filetest_partition_via_api_leaves_content_type_unset_when_not_given— guards the unchanged defaultThey assert on the request object actually handed to
General.partition, following themethod_mockpattern the surrounding tests already use.Verification
test_api.py(20 pre-existing + 3 new).test_api.py,test_md.py,test_text.pyandtest_json.pythe failure set is identical before and after; passing count goes 193 → 196, exactly the 3 added tests. (2 pre-existing failures are environmental and unrelated.)ruff checkandruff format --checkclean on both changed files.partition/api.py: none touches it (feat: add max_page to chunk_by_title and remove multipage_sections #4382 modifiestest_api.pyonly, for chunking).Independent of #4483 and #4488; all three are cut from
mainand touch different files.