Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/bedrock_agentcore/runtime/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextvars import ContextVar
from typing import Any, Callable, Dict, Optional

from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field

from ..config_bundle.bundle import ConfigBundleRef

Expand All @@ -21,10 +21,7 @@ class RequestContext(BaseModel):
request_headers: Optional[Dict[str, str]] = Field(None)
request: Optional[Any] = Field(None, description="The underlying Starlette request object")

class Config:
"""Allow non-serializable types like Starlette Request."""

arbitrary_types_allowed = True
model_config = ConfigDict(arbitrary_types_allowed=True)


class BedrockAgentCoreContext:
Expand Down
16 changes: 16 additions & 0 deletions tests/bedrock_agentcore/runtime/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ def test_request_context_allows_arbitrary_types(self):

assert context.request is mock_request

def test_request_context_no_pydantic_v1_deprecation_warning(self):
"""RequestContext must not raise PydanticDeprecatedSince20 on instantiation.

Regression guard: class-based Config triggers this warning in Pydantic v2;
ConfigDict does not. If someone reverts the fix, this test will fail.
"""
import warnings

from pydantic import PydanticDeprecatedSince20

with warnings.catch_warnings():
warnings.simplefilter("error", PydanticDeprecatedSince20)
context = RequestContext(session_id="regression-check", request_headers={"X-Test": "1"})

assert context.session_id == "regression-check"


class TestBedrockAgentCoreContextConfigBundles:
"""Tests for config bundle ContextVar methods on BedrockAgentCoreContext."""
Expand Down