diff --git a/backend/python/app/sources/external/microsoft/one_note/one_note.py b/backend/python/app/sources/external/microsoft/one_note/one_note.py index 76dbc9ad19..1438360bcf 100644 --- a/backend/python/app/sources/external/microsoft/one_note/one_note.py +++ b/backend/python/app/sources/external/microsoft/one_note/one_note.py @@ -1,5 +1,3 @@ - - import json import logging from dataclasses import asdict @@ -8785,38 +8783,53 @@ async def me_onenote_notebooks_sections_delete_pages_content( """ # Build query parameters including OData for OneNote try: - # Use typed query parameters - query_params = RequestConfiguration() + # Collect query parameters using a single dictionary for improved efficiency + query_params_dict = {} + # Set query parameters using typed object properties if select: - query_params.select = select if isinstance(select, list) else [select] + query_params_dict['select'] = select if isinstance(select, list) else [select] if expand: - query_params.expand = expand if isinstance(expand, list) else [expand] + query_params_dict['expand'] = expand if isinstance(expand, list) else [expand] if filter: - query_params.filter = filter + query_params_dict['filter'] = filter if orderby: - query_params.orderby = orderby + query_params_dict['orderby'] = orderby if search: - query_params.search = search + query_params_dict['search'] = search if top is not None: - query_params.top = top + query_params_dict['top'] = top if skip is not None: - query_params.skip = skip + query_params_dict['skip'] = skip + + # Only instantiate once if any parameter present + if query_params_dict: + query_params = RequestConfiguration() + for k, v in query_params_dict.items(): + setattr(query_params, k, v) + else: + query_params = None + # Create proper typed request configuration config = RequestConfiguration() - config.query_parameters = query_params + if query_params is not None: + config.query_parameters = query_params - if headers: - config.headers = headers + if headers is not None: + config.headers = headers.copy() + # Only set ConsistencyLevel if search and config.headers is set # Add consistency level for search operations in OneNote if search: - if not config.headers: + if config.headers is None: config.headers = {} config.headers['ConsistencyLevel'] = 'eventual' - response = await self.client.me.onenote.notebooks.by_notebook_id(notebook_id).sections.by_onenote_section_id(onenoteSection_id).pages.by_onenote_page_id(onenotePage_id).content.delete(request_configuration=config) + response = await self.client.me.onenote.notebooks.by_notebook_id(notebook_id) \ + .sections.by_onenote_section_id(onenoteSection_id) \ + .pages.by_onenote_page_id(onenotePage_id) \ + .content.delete(request_configuration=config) return self._handle_onenote_response(response) except Exception as e: return OneNoteResponse(