The default for RequestConfiguration.headers is an instance of HeadersCollection. This is created at class definition time, meaning that all instances of RequestConfiguration share the same instance of HeadersCollection by default. This leads to conflict when different instances of RequestConfiguration add/remove headers.
|
@dataclass |
|
class RequestConfiguration(Generic[QueryParameters]): |
|
""" |
|
Configuration for the request such as headers, query parameters, and middleware options. |
|
""" |
|
# Request headers |
|
headers: HeadersCollection = HeadersCollection() |
Instead, a factory should be used so that a new instance is created:
from dataclasses import dataclass, field
from typing import Generic, Optional, TypeVar
QueryParameters = TypeVar("QueryParameters")
@dataclass
class RequestConfiguration(Generic[QueryParameters]):
headers: HeadersCollection = field(default_factory=HeadersCollection)
options: Optional[list[RequestOption]] = None
query_parameters: Optional[QueryParameters] = None
The same/similar issue also affects HeadersInspectionHandlerOption init param defaults.
|
class HeadersInspectionHandlerOption(RequestOption): |
|
"""Config options for the HeaderInspectionHandler""" |
|
|
|
HEADERS_INSPECTION_HANDLER_OPTION_KEY = "HeadersInspectionHandlerOption" |
|
|
|
def __init__( |
|
self, |
|
inspect_request_headers: bool = True, |
|
inspect_response_headers: bool = True, |
|
request_headers: HeadersCollection = HeadersCollection(), |
|
response_headers: HeadersCollection = HeadersCollection(), |
The default for
RequestConfiguration.headersis an instance ofHeadersCollection. This is created at class definition time, meaning that all instances ofRequestConfigurationshare the same instance ofHeadersCollectionby default. This leads to conflict when different instances ofRequestConfigurationadd/remove headers.kiota-python/packages/abstractions/kiota_abstractions/base_request_configuration.py
Lines 16 to 22 in 806c946
Instead, a factory should be used so that a new instance is created:
The same/similar issue also affects
HeadersInspectionHandlerOptioninit param defaults.kiota-python/packages/http/httpx/kiota_http/middleware/options/headers_inspection_handler_option.py
Lines 10 to 20 in 806c946