Python: preserve shared Annotated parameter metadata - #14452
NS Agent (nslabhwan) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The changes are covered by regression tests and no unresolved issues remain.
Pull request overview
Fixes mutation of caller-owned Annotated metadata during kernel function parameter parsing.
Changes:
- Copies metadata dictionaries before parsing mutations.
- Adds regression coverage for reused metadata dictionaries.
File summaries
| File | Description |
|---|---|
python/tests/unit/functions/test_kernel_function_decorators.py |
Verifies descriptions and shared metadata remain intact. |
python/semantic_kernel/functions/kernel_function_decorator.py |
Prevents mutation of caller-owned metadata. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
CI note: the two failing workflow checks ( |
|
@microsoft-github-policy-service agree |
|
@microsoft/octo-semantickernel-pr-python could you please review this focused Python bug fix when convenient? The CLA is now complete. The two red workflow checks are the existing fork-PR environment-gate regression tracked in #14438; the changed Python area passes |
Motivation and Context
Fixes #14441.
@kernel_functioncurrently mutates caller-owned dict metadata insidetyping.Annotatedwhen_parse_parameter()extractsdescriptionwithpop(). Reusing the same metadata dict therefore loses the description after the first decoration and leaves the caller's dict modified.Description
Copy dict metadata before the existing parsing logic mutates it. This keeps the current
pop()/update()behavior local to the parser while preserving the caller-owned object.Adds a regression test that reuses one metadata dict across two
@kernel_functiondecorators and verifies that both functions retain the description and the original dict remains unchanged.Validation run locally:
pytest -q tests/unit/functions— passedruff check semantic_kernel/functions/kernel_function_decorator.py tests/unit/functions/test_kernel_function_decorators.py— passedruff format --check semantic_kernel/functions/kernel_function_decorator.py tests/unit/functions/test_kernel_function_decorators.py— passedContribution Checklist