From 17bc4ecf78d5cf4b4f31875e0048ed09819018de Mon Sep 17 00:00:00 2001 From: inchang-ing <197932532+inchang-ing@users.noreply.github.com> Date: Wed, 14 Oct 2026 00:10:34 +0800 Subject: [PATCH 1/2] FIX: honor overwrite=False for default execution settings in PromptTemplateConfig add_execution_settings() checked membership with settings.service_id (None for the default service) but stored under settings.service_id or DEFAULT_SERVICE_NAME. The mismatch meant the None key never matched, so overwrite=False never protected the "default" entry. Use the same resolved key for both the check and the store, and emit the "already exist" warning only when the add is actually refused. fixes #14582 --- .../prompt_template/prompt_template_config.py | 9 ++++--- .../prompt_template/test_prompt_templates.py | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/python/semantic_kernel/prompt_template/prompt_template_config.py b/python/semantic_kernel/prompt_template/prompt_template_config.py index 7124f73e5e38..36eba0a5851f 100644 --- a/python/semantic_kernel/prompt_template/prompt_template_config.py +++ b/python/semantic_kernel/prompt_template/prompt_template_config.py @@ -71,10 +71,13 @@ def rewrite_execution_settings( def add_execution_settings(self, settings: PromptExecutionSettings, overwrite: bool = True) -> None: """Add execution settings to the prompt template.""" - if settings.service_id in self.execution_settings and not overwrite: + # 用与存储一致的 key 做存在性检查: service_id 为 None 时实际存的是 DEFAULT_SERVICE_NAME, + # 若用 service_id(None) 检查则永远命中不到, overwrite=False 会失效(见 issue #14582)。 + key = settings.service_id or DEFAULT_SERVICE_NAME + if key in self.execution_settings and not overwrite: + logger.warning("Execution settings already exist and overwrite is set to False") return - self.execution_settings[settings.service_id or DEFAULT_SERVICE_NAME] = settings - logger.warning("Execution settings already exist and overwrite is set to False") + self.execution_settings[key] = settings def get_kernel_parameter_metadata(self) -> Sequence[KernelParameterMetadata]: """Get the kernel parameter metadata for the input variables.""" diff --git a/python/tests/unit/prompt_template/test_prompt_templates.py b/python/tests/unit/prompt_template/test_prompt_templates.py index 80e345f2431c..61916c5c8033 100644 --- a/python/tests/unit/prompt_template/test_prompt_templates.py +++ b/python/tests/unit/prompt_template/test_prompt_templates.py @@ -2,6 +2,7 @@ import json +import logging import yaml from pytest import raises @@ -72,6 +73,32 @@ def test_add_execution_settings_with_overwrite(): assert config.execution_settings["test"].extension_data["setting_value"] == "new_value2" +def test_add_execution_settings_no_overwrite_default_service(): + """overwrite=False protects the entry stored under DEFAULT_SERVICE_NAME (service_id is None).""" + config = PromptTemplateConfig(template="Example template") + first = PromptExecutionSettings(extension_data={"temperature": 0.1}) + config.add_execution_settings(first) + assert config.execution_settings["default"] == first + + second = PromptExecutionSettings(extension_data={"temperature": 0.9}) + config.add_execution_settings(second, overwrite=False) + assert config.execution_settings["default"].extension_data["temperature"] == 0.1 + + +def test_add_execution_settings_warning_only_when_refused(caplog): + """The "already exists" warning is emitted only when an add is refused, not after every add.""" + with caplog.at_level(logging.WARNING): + config = PromptTemplateConfig(template="Example template") + settings = PromptExecutionSettings(extension_data={"temperature": 0.1}) + config.add_execution_settings(settings, overwrite=False) + assert "overwrite is set to False" not in caplog.text + + caplog.clear() + other = PromptExecutionSettings(extension_data={"temperature": 0.9}) + config.add_execution_settings(other, overwrite=False) + assert "overwrite is set to False" in caplog.text + + def test_get_kernel_parameter_metadata_empty(): config = PromptTemplateConfig(template="Example template") metadata = config.get_kernel_parameter_metadata() From 9d31d1781ac9f053311ff2ed742dc38d4c24fe6c Mon Sep 17 00:00:00 2001 From: inchang-ing <291394088@qq.com> Date: Tue, 27 Oct 2026 03:07:37 +0800 Subject: [PATCH 2/2] Comment cleanup: translate the execution-settings rationale to English Keep code comments under python/semantic_kernel English-only so the maintenance context stays accessible to every contributor. --- .../prompt_template/prompt_template_config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/semantic_kernel/prompt_template/prompt_template_config.py b/python/semantic_kernel/prompt_template/prompt_template_config.py index 36eba0a5851f..da836c173cca 100644 --- a/python/semantic_kernel/prompt_template/prompt_template_config.py +++ b/python/semantic_kernel/prompt_template/prompt_template_config.py @@ -71,8 +71,9 @@ def rewrite_execution_settings( def add_execution_settings(self, settings: PromptExecutionSettings, overwrite: bool = True) -> None: """Add execution settings to the prompt template.""" - # 用与存储一致的 key 做存在性检查: service_id 为 None 时实际存的是 DEFAULT_SERVICE_NAME, - # 若用 service_id(None) 检查则永远命中不到, overwrite=False 会失效(见 issue #14582)。 + # Check existence with the same key that storage uses: when service_id is None the settings are + # stored under DEFAULT_SERVICE_NAME, so testing service_id (None) never matches and overwrite=False + # silently has no effect (see issue #14582). key = settings.service_id or DEFAULT_SERVICE_NAME if key in self.execution_settings and not overwrite: logger.warning("Execution settings already exist and overwrite is set to False")