Batch requests erroneously omit empty arrays
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with Microsoft\Graph\Core\Requests\BatchRequestBuilder::postAsync() and toPostRequestInformation(), then follow setContentFromParsable() to the JSON serialization writer. Reproduce the batch output shown in the issue and inspect JsonSerializationWriter.php around lines 355-363. Done means an empty otherMails array remains in the serialized batch request.
Written by the indexing model from the issue text.
Description
Describe the bug
When using this SDK (composer require microsoft/microsoft-graph-core) to perform JSON batching, the serialization process omits empty arrays. This behavior can cause requests to indicate success (204 response code) even though the desired operation did not occur.
Expected behavior
As a prime example, clearing a user's otherMails attribute requires supplying an empty array (a null value will cause an error here) and that empty array should be transmitted as part of the request.
Making such a direct (non-batch) request retains the empty array (otherMails: []) and the call works as expected. A batch version of such a request should do the same, instead of omitting the empty array.
How to reproduce
Here is a basic code example (using composer require microsoft/microsoft-graph) that illustrates the difference:
<?php
require_once('vendor/autoload.php');
$graphServiceClient = new Microsoft\Graph\GraphServiceClient(new Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext('TenantId','clientId','clientSecret'));
$batch = [];
$requestBody = new Microsoft\Graph\Generated\Models\User();
$requestBody->setOtherMails([]);
$batch[] = $graphServiceClient->me()->toPatchRequestInformation($requestBody);
$batchRequestContent = new Microsoft\Graph\Core\Requests\BatchRequestContent($batch);
$batchRequestBuilder = new Microsoft\Graph\BatchRequestBuilder($graphServiceClient->getRequestAdapter());
error_log('after batch serialization');
print_r(array_map(fn($r) => $r->body, json_decode($batchRequestBuilder->toPostRequestInformation($batchRequestContent)->content->getContents())->requests));
error_log('original batch content');
print_r(array_map(fn($b) => json_decode($b->content->getContents()), $batch));
Example output:
after batch serialization
Array
(
[0] => stdClass Object
(
[@odata.type] => #microsoft.graph.user
)
)
original batch content
Array
(
[0] => stdClass Object
(
[@odata.type] => #microsoft.graph.user
[otherMails] => Array
(
)
)
)
SDK Version
2.3
Latest version known to work for scenario above?
No response
Known Workarounds
No response
Debug output
No response
Configuration
No response
Other information
Trace of the problem:
- Microsoft\Graph\Core\Requests\BatchRequestBuilder->postAsync() calls $this->toPostRequestInformation()
- which calls $requestInfo->setContentFromParsable() using the supplied requestAdapter
- which calls $requestAdapter->getSerializationWriterFactory()->getSerializationWriter()
- which is an instance of Microsoft\Kiota\Serialization\Json\JsonSerializationWriter
- which omits empty arrays
- Dominant language
- PHP
- Stars
- 16
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoftgraph/msgraph-sdk-php-core
-
status:waiting-for-triage type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoftgraph/msgraph-sdk-php-core#230 · 1 comment ·
-
status:waiting-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoftgraph/msgraph-sdk-php-core#227 · 2 comments · 1 reaction ·
-
area:authentication goodfirstissue type:enhancement
microsoftgraph/msgraph-sdk-php-core#202 · 4 comments · 1 assignee ·
-
type:feature
Difficulty 4/5 3-5 days Newbie friendliness 35/100
microsoftgraph/msgraph-sdk-php-core#195 · 2 comments ·
-
microsoftgraph/msgraph-sdk-php-core#132 · 1 comment · 1 assignee ·
All issues in microsoftgraph/msgraph-sdk-php-core
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
coollabsio/coolify#11927 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100