44from kiota_abstractions .request_adapter import RequestAdapter
55from kiota_abstractions .request_information import RequestInformation
66from kiota_abstractions .method import Method
7- from kiota_abstractions .serialization import Parsable
7+ from kiota_abstractions .serialization import Parsable , ParsableFactory
88from kiota_abstractions .headers_collection import HeadersCollection
99from kiota_abstractions .api_error import APIError
1010
@@ -26,7 +26,7 @@ class BatchRequestBuilder:
2626 def __init__ (
2727 self ,
2828 request_adapter : RequestAdapter ,
29- error_map : Optional [Dict [str , Type [Parsable ]]] = None
29+ error_map : Optional [Dict [str , Type [ParsableFactory ]]] = None
3030 ):
3131 if request_adapter is None :
3232 raise ValueError ("request_adapter cannot be Null." )
@@ -37,20 +37,19 @@ def __init__(
3737 async def post (
3838 self ,
3939 batch_request_content : Union [BatchRequestContent , BatchRequestContentCollection ],
40- error_map : Optional [Dict [str , Type [Parsable ]]] = None ,
41- ) -> Union [T , BatchResponseContentCollection ]:
40+ error_map : Optional [Dict [str , Type [ParsableFactory ]]] = None ,
41+ ) -> Union [BatchResponseContent , BatchResponseContentCollection ]:
4242 """
4343 Sends a batch request and returns the batch response content.
44-
44+
4545 Args:
46- batch_request_content (Union[BatchRequestContent,
46+ batch_request_content (Union[BatchRequestContent,
4747 BatchRequestContentCollection]): The batch request content.
48- response_type: Optional[Type[T]] : The type to deserialize the response into.
49- Optional[Dict[str, Type[Parsable]]] = None:
48+ Optional[Dict[str, Type[ParsableFactory]]] = None:
5049 Error mappings for response handling.
5150
5251 Returns:
53- Union[T , BatchResponseContentCollection]: The batch response content
52+ Union[BatchResponseContent , BatchResponseContentCollection]: The batch response content
5453 or the specified response type.
5554
5655 """
@@ -60,11 +59,6 @@ async def post(
6059
6160 if isinstance (batch_request_content , BatchRequestContent ):
6261 request_info = await self .to_post_request_information (batch_request_content )
63- bytes_content = request_info .content
64- json_content = bytes_content .decode ("utf-8" )
65- updated_str = '{"requests":' + json_content + '}'
66- updated_bytes = updated_str .encode ("utf-8" )
67- request_info .content = updated_bytes
6862 error_map = error_map or self .error_map
6963 response = None
7064 try :
@@ -87,15 +81,15 @@ async def post(
8781 async def _post_batch_collection (
8882 self ,
8983 batch_request_content_collection : BatchRequestContentCollection ,
90- error_map : Optional [Dict [str , Type [Parsable ]]] = None ,
84+ error_map : Optional [Dict [str , Type [ParsableFactory ]]] = None ,
9185 ) -> BatchResponseContentCollection :
9286 """
9387 Sends a collection of batch requests and returns a collection of batch response contents.
94-
88+
9589 Args:
96- batch_request_content_collection (BatchRequestContentCollection): The
90+ batch_request_content_collection (BatchRequestContentCollection): The
9791 collection of batch request contents.
98- Optional[Dict[str, Type[Parsable ]]] = None:
92+ Optional[Dict[str, Type[ParsableFactory ]]] = None:
9993 Error mappings for response handling.
10094
10195 Returns:
@@ -108,7 +102,8 @@ async def _post_batch_collection(
108102 batch_requests = batch_request_content_collection .get_batch_requests_for_execution ()
109103 for batch_request_content in batch_requests :
110104 response = await self .post (batch_request_content , error_map )
111- batch_responses .add_response (response )
105+ if isinstance (response , BatchResponseContent ):
106+ batch_responses .add_response (response )
112107
113108 return batch_responses
114109
@@ -117,7 +112,7 @@ async def to_post_request_information(
117112 ) -> RequestInformation :
118113 """
119114 Creates request information for a batch POST request.
120-
115+
121116 Args:
122117 batch_request_content (BatchRequestContent): The batch request content.
123118
@@ -127,15 +122,14 @@ async def to_post_request_information(
127122
128123 if batch_request_content is None :
129124 raise ValueError ("batch_request_content cannot be Null." )
130- batch_request_items = list (batch_request_content .requests .values ())
131125
132126 request_info = RequestInformation ()
133127 request_info .http_method = Method .POST
134128 request_info .url_template = self .url_template
135129 request_info .headers = HeadersCollection ()
136130 request_info .headers .try_add ("Content-Type" , APPLICATION_JSON )
137131 request_info .set_content_from_parsable (
138- self ._request_adapter , APPLICATION_JSON , batch_request_items
132+ self ._request_adapter , APPLICATION_JSON , batch_request_content
139133 )
140134
141135 return request_info
0 commit comments