4
4
from kiota_abstractions .request_adapter import RequestAdapter
5
5
from kiota_abstractions .request_information import RequestInformation
6
6
from kiota_abstractions .method import Method
7
- from kiota_abstractions .serialization import Parsable
7
+ from kiota_abstractions .serialization import Parsable , ParsableFactory
8
8
from kiota_abstractions .headers_collection import HeadersCollection
9
9
from kiota_abstractions .api_error import APIError
10
10
@@ -26,7 +26,7 @@ class BatchRequestBuilder:
26
26
def __init__ (
27
27
self ,
28
28
request_adapter : RequestAdapter ,
29
- error_map : Optional [Dict [str , Type [Parsable ]]] = None
29
+ error_map : Optional [Dict [str , Type [ParsableFactory ]]] = None
30
30
):
31
31
if request_adapter is None :
32
32
raise ValueError ("request_adapter cannot be Null." )
@@ -37,20 +37,19 @@ def __init__(
37
37
async def post (
38
38
self ,
39
39
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 ]:
42
42
"""
43
43
Sends a batch request and returns the batch response content.
44
-
44
+
45
45
Args:
46
- batch_request_content (Union[BatchRequestContent,
46
+ batch_request_content (Union[BatchRequestContent,
47
47
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:
50
49
Error mappings for response handling.
51
50
52
51
Returns:
53
- Union[T , BatchResponseContentCollection]: The batch response content
52
+ Union[BatchResponseContent , BatchResponseContentCollection]: The batch response content
54
53
or the specified response type.
55
54
56
55
"""
@@ -60,11 +59,6 @@ async def post(
60
59
61
60
if isinstance (batch_request_content , BatchRequestContent ):
62
61
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
68
62
error_map = error_map or self .error_map
69
63
response = None
70
64
try :
@@ -87,15 +81,15 @@ async def post(
87
81
async def _post_batch_collection (
88
82
self ,
89
83
batch_request_content_collection : BatchRequestContentCollection ,
90
- error_map : Optional [Dict [str , Type [Parsable ]]] = None ,
84
+ error_map : Optional [Dict [str , Type [ParsableFactory ]]] = None ,
91
85
) -> BatchResponseContentCollection :
92
86
"""
93
87
Sends a collection of batch requests and returns a collection of batch response contents.
94
-
88
+
95
89
Args:
96
- batch_request_content_collection (BatchRequestContentCollection): The
90
+ batch_request_content_collection (BatchRequestContentCollection): The
97
91
collection of batch request contents.
98
- Optional[Dict[str, Type[Parsable ]]] = None:
92
+ Optional[Dict[str, Type[ParsableFactory ]]] = None:
99
93
Error mappings for response handling.
100
94
101
95
Returns:
@@ -108,7 +102,8 @@ async def _post_batch_collection(
108
102
batch_requests = batch_request_content_collection .get_batch_requests_for_execution ()
109
103
for batch_request_content in batch_requests :
110
104
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 )
112
107
113
108
return batch_responses
114
109
@@ -117,7 +112,7 @@ async def to_post_request_information(
117
112
) -> RequestInformation :
118
113
"""
119
114
Creates request information for a batch POST request.
120
-
115
+
121
116
Args:
122
117
batch_request_content (BatchRequestContent): The batch request content.
123
118
@@ -127,15 +122,14 @@ async def to_post_request_information(
127
122
128
123
if batch_request_content is None :
129
124
raise ValueError ("batch_request_content cannot be Null." )
130
- batch_request_items = list (batch_request_content .requests .values ())
131
125
132
126
request_info = RequestInformation ()
133
127
request_info .http_method = Method .POST
134
128
request_info .url_template = self .url_template
135
129
request_info .headers = HeadersCollection ()
136
130
request_info .headers .try_add ("Content-Type" , APPLICATION_JSON )
137
131
request_info .set_content_from_parsable (
138
- self ._request_adapter , APPLICATION_JSON , batch_request_items
132
+ self ._request_adapter , APPLICATION_JSON , batch_request_content
139
133
)
140
134
141
135
return request_info
0 commit comments