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..e6404afb80 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 @@ -17893,38 +17891,52 @@ async def users_onenote_sections_create_pages( """ # Build query parameters including OData for OneNote try: - # Use typed query parameters - query_params = RequestConfiguration() - # Set query parameters using typed object properties - if select: - query_params.select = select if isinstance(select, list) else [select] - if expand: - query_params.expand = expand if isinstance(expand, list) else [expand] - if filter: - query_params.filter = filter - if orderby: - query_params.orderby = orderby - if search: - query_params.search = search - if top is not None: - query_params.top = top - if skip is not None: - query_params.skip = skip + # Track only supplied params to avoid repeated attribute setting + needs_query = ( + select is not None + or expand is not None + or filter is not None + or orderby is not None + or search is not None + or top is not None + or skip is not None + ) - # Create proper typed request configuration + query_params = None + if needs_query: + query_params = RequestConfiguration() + # Set query parameters using typed object properties + if select: + query_params.select = select if isinstance(select, list) else [select] + if expand: + query_params.expand = expand if isinstance(expand, list) else [expand] + if filter: + query_params.filter = filter + if orderby: + query_params.orderby = orderby + if search: + query_params.search = search + if top is not None: + query_params.top = top + if skip is not None: + query_params.skip = skip + + # Create configuration and assign query_parameters only if needed config = RequestConfiguration() - config.query_parameters = query_params + if query_params is not None: + config.query_parameters = query_params if headers: - config.headers = headers + config.headers = headers.copy() if not hasattr(headers, "copy") else headers.copy() - # Add consistency level for search operations in OneNote if search: - if not config.headers: + if not hasattr(config, 'headers') or config.headers is None: config.headers = {} config.headers['ConsistencyLevel'] = 'eventual' - response = await self.client.users.by_user_id(user_id).onenote.sections.by_onenote_section_id(onenoteSection_id).pages.post(body=request_body, request_configuration=config) + response = await self.client.users.by_user_id(user_id).onenote.sections.by_onenote_section_id(onenoteSection_id).pages.post( + body=request_body, request_configuration=config + ) return self._handle_onenote_response(response) except Exception as e: return OneNoteResponse(