Skip to content

fix(abstractions): allow empty part values and relax adapter requirement in MultipartBody - #841

Open
Hardik K (hardikkaurani) wants to merge 3 commits into
microsoft:mainfrom
hardikkaurani:fix/multipart-body-empty-values-and-serialization
Open

Hardik K (hardikkaurani) wants to merge 3 commits into
microsoft:mainfrom
hardikkaurani:fix/multipart-body-empty-values-and-serialization

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Overview

This pull request improves MultipartBody in kiota_abstractions:

  1. Empty part value support:

    • MultipartBody.add_or_replace_part previously checked if 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 raised ValueError: Part value cannot be null.
    • Updated the check to 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).
  2. Scoped request_adapter requirement:

    • MultipartBody.serialize previously unconditionally required self.request_adapter and its serialization writer factory, raising ValueError even when all parts were primitive types (str, bytes, io.IOBase).
    • request_adapter is now only checked when at least one part is an instance of Parsable (which requires the adapter's factory to serialize).
  3. Method typo fix:

    • Corrected internal helper typo _get_comtent_disposition to _get_content_disposition.
    • Retained _get_comtent_disposition = _get_content_disposition for backwards compatibility.

Changes

  • packages/abstractions/kiota_abstractions/multipart_body.py:
    • Check if part_value is None: in add_or_replace_part.
    • Only require request_adapter in serialize if a Parsable part is present.
    • Fix method typo in _get_content_disposition with backwards-compatible alias.
  • packages/abstractions/tests/test_multipart_body.py:
    • Add regression tests verifying empty bytes and str parts can be added and retrieved.
    • Add test verifying serialization of non-parsable parts without requiring request_adapter.
    • Add test verifying Parsable parts still validate request_adapter presence.
    • Add test for _get_content_disposition and its alias.

Testing Instructions

  • From 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.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 17:51
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 1, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
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!

@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants