Title: BatchRequestBuilder doesn't copy headers from BatchRequestContent on post · Issue #831 · microsoftgraph/msgraph-sdk-python-core · GitHub
Open Graph Title: BatchRequestBuilder doesn't copy headers from BatchRequestContent on post · Issue #831 · microsoftgraph/msgraph-sdk-python-core
X Title: BatchRequestBuilder doesn't copy headers from BatchRequestContent on post · Issue #831 · microsoftgraph/msgraph-sdk-python-core
Description: Describe the bug I'm trying to send a batch request from UsersRequestBuilder and GroupsRequestBuilder objects that use the ConsistencyLevel: eventual header. The RequestInformation objects loaded in the BatchRequestContent include the he...
Open Graph Description: Describe the bug I'm trying to send a batch request from UsersRequestBuilder and GroupsRequestBuilder objects that use the ConsistencyLevel: eventual header. The RequestInformation objects loaded i...
X Description: Describe the bug I'm trying to send a batch request from UsersRequestBuilder and GroupsRequestBuilder objects that use the ConsistencyLevel: eventual header. The RequestInformation objects load...
Opengraph URL: https://github.com/microsoftgraph/msgraph-sdk-python-core/issues/831
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BatchRequestBuilder doesn't copy headers from BatchRequestContent on post","articleBody":"### Describe the bug\n\nI'm trying to send a batch request from `UsersRequestBuilder` and `GroupsRequestBuilder` objects that use the `ConsistencyLevel: eventual` header. The `RequestInformation` objects loaded in the `BatchRequestContent` include the header, but then when calling to the `post` method of the `BatchRequestBuilder` it doesn't copy the headers, just creates the `Content-Type` header, resulting on a 400 error from the server.\n\nThe bug itself is in the following lines:\n\nhttps://github.com/microsoftgraph/msgraph-sdk-python-core/blob/df7bdbfb7e4268df10606f2b35623ecff559fe00/src/msgraph_core/requests/batch_request_builder.py#L126-L135\n\n### Expected behavior\n\nThe `to_post_request_information` method from `BatchRequestBuilder` should copy the headers from the provided `BatchRequestContent` object\n\n### How to reproduce\n\nYou can reproduce it using the following snippet\n\n```Python\nimport base64\n\nfrom typing import Optional\n\nfrom azure.keyvault.secrets import SecretClient\nfrom azure.identity import CertificateCredential, ManagedIdentityCredential\nfrom kiota_abstractions.base_request_configuration import RequestConfiguration\nfrom msgraph.generated.users.users_request_builder import UsersRequestBuilder\nfrom msgraph.graph_service_client import GraphServiceClient\nfrom msgraph_core.requests.batch_request_builder import BatchRequestBuilder\nfrom msgraph_core.requests.batch_request_content import BatchRequestContent\nfrom msgraph_core.requests.batch_request_item import BatchRequestItem\n\n\ndef get_tenant_credential(tenant_id, client_id, cert_name):\n url = \"https://\u003cYOUR VAULT URL\u003e.vault.azure.net/\"\n credential = ManagedIdentityCredential(\n client_id=\"\u003cYOUR CLIENT ID\u003e\"\n )\n key_vault_client = SecretClient(vault_url=url, credential=credential)\n secret = key_vault_client.get_secret(cert_name).value\n cert_bytes = base64.b64decode(secret)\n return CertificateCredential(\n tenant_id=tenant_id,\n client_id=client_id,\n certificate_data=cert_bytes,\n send_certificate_chain=True\n )\n\n\ndef get_graph_client():\n tenant = \"\u003cYOUR TENANT\u003e\"\n client_id = \"\u003cYOUR GRAPH CLIENT ID\u003e\"\n cert_name = \"\u003cYOUR GRAPH CERT NAME\u003e\"\n credential = get_tenant_credential(tenant, client_id, cert_name)\n scopes = [\"https://graph.microsoft.com/.default\"]\n return GraphServiceClient(credential, scopes)\n\n\ndef build_query_filters(\n domains: list[str],\n fields: Optional[list[str]] = None,\n search_term: Optional[str] = None,\n excluded_ids: Optional[set[str]] = None,\n) -\u003e str:\n filter_list = [f\"endswith(mail, '@{d}')\" for d in domains]\n filters = f\"({' or '.join(filter_list)})\"\n\n if search_term:\n if fields is None:\n fields = ['displayName', 'mail']\n\n search_filter_list = [f\"startswith({f}, '{search_term}')\"\n for f in fields]\n search_filters = f\"({' or '.join(search_filter_list)})\"\n filters = f\"{filters} and {search_filters}\"\n\n if excluded_ids:\n exclusion_list = [f\"id ne '{i}'\" for i in excluded_ids]\n excluded_filter = f\"{' and '.join(exclusion_list)}\"\n filters = f\"{filters} and {excluded_filter}\"\n return filters\n\n\ndef build_users_request_config(\n search_term: Optional[str] = None,\n n_items: Optional[int] = None,\n excluded_ids: Optional[set[str]] = None,\n) -\u003e RequestConfiguration:\n domains = [\"microsoft.com\", \"linkedin.biz\", \"*.microsoft.com\"]\n filters = build_query_filters(\n domains,\n search_term=search_term,\n excluded_ids=excluded_ids,\n )\n query_params = UsersRequestBuilder.UsersRequestBuilderGetQueryParameters(\n select=['id', 'displayName', 'mail'],\n filter=filters,\n top=n_items,\n count=True,\n )\n request_config = RequestConfiguration(query_parameters=query_params)\n request_config.headers.add(\"ConsistencyLevel\", \"eventual\")\n return request_config\n\n\nasync def search(search_term: str, n_items: int = 5):\n client = get_graph_client()\n request_adapter = client.request_adapter\n\n # Build user request batch item\n user_request_config = build_users_request_config(search_term, n_items)\n user_request_builder = UsersRequestBuilder(request_adapter, {})\n user_request_info = user_request_builder.to_get_request_information(\n user_request_config\n )\n user_request_item = BatchRequestItem(user_request_info)\n\n # Build group request batch item\n # group_request_config = build_groups_request_config(\n # search_term, n_items\n # )\n # group_request_builder = GroupsRequestBuilder(request_adapter, {})\n # group_request_info = group_request_builder.to_get_request_information(\n # group_request_config\n # )\n # group_request_item = BatchRequestItem(group_request_info)\n\n # Create batch request content\n batch_request_content = BatchRequestContent({\n user_request_item.id: user_request_item,\n # group_request_item.id: group_request_item\n })\n\n batch_request_builder = BatchRequestBuilder(request_adapter)\n batch_result = await batch_request_builder.post(batch_request_content)\n return batch_result\n\n\nif __name__ == \"__main__\":\n import asyncio\n\n search_term = \"test\"\n n_items = 5\n loop = asyncio.get_event_loop()\n results = loop.run_until_complete(search(search_term, n_items))\n print(results)\n```\n\n### SDK Version\n\n1.15.0\n\n### Latest version known to work for scenario above?\n\n_No response_\n\n### Known Workarounds\n\nThere's no workaround possible, given the request information is created in the same method that send the post\n\n### Debug output\n\nERROR:root:API Error: \n APIError\n Code: 400\n message: The server returned an unexpected status code and no error class is registered for this code 400\n\n### Configuration\n\n_No response_\n\n### Other information\n\n_No response_","author":{"url":"https://github.com/urucoder","@type":"Person","name":"urucoder"},"datePublished":"2025-02-12T23:31:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/831/msgraph-sdk-python-core/issues/831"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e92ecb24-21d8-192c-ebeb-1ca87aaab663 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B7C2:123AEB:43D8F:5797F:6969C322 |
| html-safe-nonce | 0ceb6ffef1e5d90eb8550356e9d0fc9b16787fc36f8edfd438954295420db5ac |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0MyOjEyM0FFQjo0M0Q4Rjo1Nzk3Rjo2OTY5QzMyMiIsInZpc2l0b3JfaWQiOiIxNDg4NTE0NDU4MjkwMDc4NDk4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d9917b1048158078fd1e22d1197377c5c53e0201c1e150eaa92b080b9bad4116 |
| hovercard-subject-tag | issue:2849572678 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoftgraph/msgraph-sdk-python-core/831/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f9d1717532d41fa9729a03cd5cbff9b8f0d99866318650414fd51d60eeffc3f4/microsoftgraph/msgraph-sdk-python-core/issues/831 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f9d1717532d41fa9729a03cd5cbff9b8f0d99866318650414fd51d60eeffc3f4/microsoftgraph/msgraph-sdk-python-core/issues/831 |
| og:image:alt | Describe the bug I'm trying to send a batch request from UsersRequestBuilder and GroupsRequestBuilder objects that use the ConsistencyLevel: eventual header. The RequestInformation objects loaded i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | urucoder |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoftgraph/msgraph-sdk-python-core git https://github.com/microsoftgraph/msgraph-sdk-python-core.git |
| octolytics-dimension-user_id | 17304259 |
| octolytics-dimension-user_login | microsoftgraph |
| octolytics-dimension-repository_id | 242847794 |
| octolytics-dimension-repository_nwo | microsoftgraph/msgraph-sdk-python-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 242847794 |
| octolytics-dimension-repository_network_root_nwo | microsoftgraph/msgraph-sdk-python-core |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width