msgraph-sdk-python-core
msgraph-sdk-python-core copied to clipboard
Creating dependent batch requests results in AttributeError: 'str' object has no attribute 'id'
@shemogumbe
To reproduce:
today = datetime.now().replace(hour=0,minute=0,second=0, microsecond=0)
tomorrow = today + timedelta(days=1)
new_event = Event(
subject= "File end-of-day report",
start=DateTimeTimeZone(
date_time=(today + timedelta(hours=17)).isoformat(timespec='seconds'),
time_zone='Pacific Standard Time'
),
end=DateTimeTimeZone(
date_time=(today + timedelta(hours=17, minutes=30)).isoformat(timespec='seconds'),
time_zone='Pacific Standard Time'
)
)
# Use the request builder to generate a regular
# POST request to /me/events
add_event_request = graph_client.me.events.to_post_request_information(new_event)
# Use the request builder to generate a regular
# request to /me/calendarview?startDateTime="start"&endDateTime="end"
query_params = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetQueryParameters(
start_date_time=today.isoformat(timespec='seconds'),
end_date_time=tomorrow.isoformat(timespec='seconds')
)
config = CalendarViewRequestBuilder.CalendarViewRequestBuilderGetRequestConfiguration(
query_parameters=query_params
)
events_request = graph_client.me.calendar_view.to_get_request_information(config)
# Build the batch
add_event_batch_item = BatchRequestItem(request_information=add_event_request)
events_batch_item = BatchRequestItem(request_information=events_request, depends_on=[add_event_batch_item])
batch_request_content = BatchRequestContentCollection()
batch_request_content.add_batch_request_item(add_event_batch_item)
batch_request_content.add_batch_request_item(events_batch_item)
The last line will throw an error:
File "/home/jasonjoh/repos/msgraph-snippets-python/src/snippets/batch_requests.py", line 98, in dependent_batch
batch_request_content.add_batch_request_item(events_batch_item)
File "/home/jasonjoh/.local/lib/python3.10/site-packages/msgraph_core/requests/batch_request_content_collection.py", line 32, in add_batch_request_item
self.current_batch.add_request(request.id, request)
File "/home/jasonjoh/.local/lib/python3.10/site-packages/msgraph_core/requests/batch_request_content.py", line 55, in add_request
if dependent_id not in [req.id for req in self.requests]:
File "/home/jasonjoh/.local/lib/python3.10/site-packages/msgraph_core/requests/batch_request_content.py", line 55, in <listcomp>
if dependent_id not in [req.id for req in self.requests]:
AttributeError: 'str' object has no attribute 'id'