Repository navigation
fix(abstractions): allow empty part values and relax adapter requirement in MultipartBody - #841
Open
Hardik K (hardikkaurani) wants to merge 3 commits into
Conversation
…es and serialization
…y.add_or_replace_part
…ire request_adapter for parsable parts
Contributor
Author
|
Hi Vincent Biret (@baywet), could you please take a look at this PR when you have a moment? It fixes MultipartBody to allow empty byte and string part values (such as zero-byte file uploads or empty form fields), relaxes the request_adapter requirement during serialization when only primitive parts are present, and fixes the _get_content_disposition typo. All unit tests, mypy, and pylint (10.00/10) pass cleanly. Thank you! |
|
This branch has not been deployed
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.



Overview
This pull request improves
MultipartBodyinkiota_abstractions:Empty part value support:
MultipartBody.add_or_replace_partpreviously checkedif not part_value:before adding a part. Because empty byte sequences (b"") and empty strings ("") are falsy in Python, attempting to add an empty file or empty text field raisedValueError: Part value cannot be null.if part_value is None:, allowing empty byte sequences and strings to be added and serialized properly (such as zero-byte file uploads or empty form fields in multipart requests).Scoped
request_adapterrequirement:MultipartBody.serializepreviously unconditionally requiredself.request_adapterand its serialization writer factory, raisingValueErroreven when all parts were primitive types (str,bytes,io.IOBase).request_adapteris now only checked when at least one part is an instance ofParsable(which requires the adapter's factory to serialize).Method typo fix:
_get_comtent_dispositionto_get_content_disposition._get_comtent_disposition = _get_content_dispositionfor backwards compatibility.Changes
packages/abstractions/kiota_abstractions/multipart_body.py:if part_value is None:inadd_or_replace_part.request_adapterinserializeif aParsablepart is present._get_content_dispositionwith backwards-compatible alias.packages/abstractions/tests/test_multipart_body.py:bytesandstrparts can be added and retrieved.request_adapter.Parsableparts still validaterequest_adapterpresence._get_content_dispositionand its alias.Testing Instructions
packages/abstractions:pytest: 198 passed (194 existing + 4 new tests).mypy kiota_abstractions: Clean (0 issues across 48 source files).pylint kiota_abstractions --disable=W --rcfile=.pylintrc: Rated 10.00/10.yapf&isort: Clean formatting.