Skip to content

Comments

Fix multipart/mixed serialization - only apply file descriptors for multipart/form-data#3778

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-submit-batch-serializer
Draft

Fix multipart/mixed serialization - only apply file descriptors for multipart/form-data#3778
Copilot wants to merge 3 commits intomainfrom
copilot/fix-submit-batch-serializer

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

multipart/mixed bodies were incorrectly serialized as file descriptor arrays, breaking operations like Azure Storage's submitBatch which expect plain string bodies.

Root Cause

TCGC sets UsageFlags.MultipartFormData for all multipart content types (multipart/mixed, multipart/form-data, etc.), but the emitter was applying file descriptor serialization unconditionally when this flag was present.

Changes

Added property-level check in buildSerializerFunction.ts to verify serializationOptions.multipart exists before applying file descriptor serialization:

const hasMultipartProperties = properties.some(
  (prop) => prop.kind === "property" && prop.serializationOptions?.multipart
);

if (
  (type.usage & UsageFlags.Input) === UsageFlags.Input &&
  (type.usage & UsageFlags.MultipartFormData) === UsageFlags.MultipartFormData &&
  hasMultipartProperties  // New condition
) {
  // Apply file descriptor serialization
}

Test Coverage

Added test case plainBody.md in test/modularUnit/scenarios/multipart/ that verifies models without HttpPart<T> properties generate serializers with property mapping ({ body: item["body"] }) rather than array-of-parts serialization ([createFilePartDescriptor(...)]).

Behavior

  • multipart/form-data with HttpPart<T>: Properties have serializationOptions.multipart → generates [createFilePartDescriptor(...)]
  • multipart/mixed with plain body: Properties lack multipart options → generates property mapping instead of file descriptors
Original prompt

This section details on the original issue you should resolve

<issue_title>Storage: generated submitBatch body serializer causes invalid input</issue_title>
<issue_description>submitBatch expects to send the body of a string with multiple requests assembled, example:

--batch_21d021b0-54e1-4e36-89b2-74da777fb5fd
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 0

DELETE /container177139184658409904/blob0 HTTP/1.1
Accept: application/xml
x-ms-date: Wed, 18 Feb 2026 05:17:26 GMT
Authorization: SharedKey 

--batch_21d021b0-54e1-4e36-89b2-74da777fb5fd
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1

DELETE /container177139184658409904/blob1 HTTP/1.1
Accept: application/xml
x-ms-date: Wed, 18 Feb 2026 05:17:26 GMT
Authorization: SharedKey 

--batch_21d021b0-54e1-4e36-89b2-74da777fb5fd
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 2

DELETE /container177139184658409904/%C3%A5%20%C3%A4%20%C3%B6 HTTP/1.1
Accept: application/xml
x-ms-date: Wed, 18 Feb 2026 05:17:26 GMT
Authorization: SharedKey 

--batch_21d021b0-54e1-4e36-89b2-74da777fb5fd--

However, our generated code sees multipart/mixed then wrap it with a file descriptor?

[{"name":"body","body":"--batch_dd27e660-ec4d-4f9d-9338-a648cf1fabaf\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 0\r\n\r\nDELETE /container177139126912603493/blob0 HTTP/1.1\r\naccept: application/json\r\nx-ms-date: Wed, 18 Feb 2026 05:07:49 GMT\r\nAuthorization: SharedKey  \r\n\r\n--batch_dd27e660-ec4d-4f9d-9338-a648cf1fabaf\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 1\r\n\r\nDELETE /container177139126912603493/blob1 HTTP/1.1\r\naccept: application/json\r\nx-ms-date: Wed, 18 Feb 2026 05:07:49 GMT\r\nAuthorization: SharedKey  \r\n\r\n--batch_dd27e660-ec4d-4f9d-9338-a648cf1fabaf\r\nContent-Type: application/http\r\nContent-Transfer-Encoding: binary\r\nContent-ID: 2\r\n\r\nDELETE /container177139126912603493/%C3%A5%20%C3%A4%20%C3%B6 HTTP/1.1\r\naccept: application/json\r\nx-ms-date: Wed, 18 Feb 2026 05:07:49 GMT\r\nAuthorization: SharedKey  \r\n\r\n--batch_dd27e660-ec4d-4f9d-9338-a648cf1fabaf--\r\n","contentType":"application/octet-stream"}]

code:

export function _submitBatchRequestSerializer(item: _SubmitBatchRequest): any {
  return [createFilePartDescriptor("body", item["body"], "application/octet-stream")];
}

The request has this content type

Content-Type: multipart/mixed; boundary=batch_21d021b0-54e1-4e36-89b2-74da777fb5fd</issue_description>

<agent_instructions>Make it so that multipart/mixed (and other non-form-data multipart types) is not treated like multipart/form-data, just give it the default handling</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: timovv <1787642+timovv@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix generated submitBatch body serializer for valid input Fix multipart/mixed serialization - only apply file descriptors for multipart/form-data Feb 18, 2026
Copilot AI requested a review from timovv February 18, 2026 18:40
(type.usage & UsageFlags.MultipartFormData) === UsageFlags.MultipartFormData
(type.usage & UsageFlags.MultipartFormData) ===
UsageFlags.MultipartFormData &&
hasMultipartProperties
Copy link
Member

Choose a reason for hiding this comment

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

@copilot add a test case with multipart/mixed to verify the new behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added test case in test/modularUnit/scenarios/multipart/plainBody.md that verifies models without HttpPart<T> properties use default serialization instead of array-of-parts serialization. The test demonstrates that plain body models generate { body: item["body"] } rather than [createFilePartDescriptor(...)]. Commit: 29ade60

Co-authored-by: timovv <1787642+timovv@users.noreply.github.com>
Copilot AI requested a review from timovv February 18, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage: generated submitBatch body serializer causes invalid input

2 participants