Skip to content

RequestConfiguration instances share the same HeadersCollection instance by default #507

Closed

Description

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(),

Activity

  1. moved this to Needs Triage 🔍 in Kiotaon Jan 12, 2026
  2. changed the title [-]HeadersCollection instances share the same HeadersCollection instance by default[/-] [+]RequestConfiguration instances share the same HeadersCollection instance by default[/+] on Jan 12, 2026
  3. HardMax71 commented on Sep 3, 2026

    @HardMax71
    Contributor

    Same here. Every RequestConfiguration() that omits headers= mutates one shared collection, and in an async service that talks to many mailboxes a Prefer added for one call rides along on the others. Reproduces on 1.10.1 and the line is unchanged in 1.12.0 and on main:

    microsoft-kiota-abstractions 1.10.1
    two configs share one HeadersCollection: True
    header added on a is visible on b: {'outlook.body-content-type=text'}
    

    Script: https://gist.github.com/HardMax71/515894a3c37374424ee77c5f3f5a1aa9

    The field(default_factory=HeadersCollection) fix in the description is the whole change, plus the same for HeadersInspectionHandlerOption. Happy to send that PR with a test if nobody has it in flight.

  4. moved this from Needs Triage 🔍 to Done ✔️ in Kiotaon Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done ✔️

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions