mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 23:16:18 +01:00
fix: runtime config update ignored by config file
Runtime settings were handed back to pydantic-settings as init settings,
which rank below the config file and the environment. Any key already
present in EOS.config.json or in the environment silently discarded the
update, so a bulk PUT /v1/config returned 200 without applying anything,
while the granular PUT /v1/config/{path} endpoint kept working.
Add a dedicated runtime settings source ranked directly below the command
line arguments and record granular updates there as well, so both
endpoints share one store that survives re-evaluation of the settings
sources. Environment variables keep precedence over the config file for
all keys that were not set at runtime.
Also repairs revert_settings() and update(), which passed their data
through the same init settings.
Closes #1303
This commit is contained in:
@@ -65,6 +65,37 @@ from akkudoktoreos.utils.datetimeutil import (
|
||||
_model_private_state: "weakref.WeakKeyDictionary[Union[PydanticBaseModel, PydanticModelNestedValueMixin], Dict[str, Any]]" = weakref.WeakKeyDictionary()
|
||||
|
||||
|
||||
def deep_merge(source_data: Any, update_data: Any) -> Any:
|
||||
"""Merge two data structures recursively.
|
||||
|
||||
Values in update_data (including None) override source values.
|
||||
Nested dictionaries are merged recursively.
|
||||
Lists in update_data replace source lists entirely.
|
||||
|
||||
Args:
|
||||
source_data (Any): Data to merge into.
|
||||
update_data (Any): Data to merge from.
|
||||
|
||||
Returns:
|
||||
Any: The merged data.
|
||||
"""
|
||||
if isinstance(source_data, dict) and isinstance(update_data, dict):
|
||||
merged = dict(source_data)
|
||||
for key, update_value in update_data.items():
|
||||
if key in merged:
|
||||
merged[key] = deep_merge(merged[key], update_value)
|
||||
else:
|
||||
merged[key] = update_value
|
||||
return merged
|
||||
|
||||
# If both are lists, replace source list with update list
|
||||
if isinstance(source_data, list) and isinstance(update_data, list):
|
||||
return update_data
|
||||
|
||||
# For other types or if update_data is None, override source_data
|
||||
return update_data
|
||||
|
||||
|
||||
def merge_models(source: BaseModel, update_dict: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Merge a Pydantic model instance with an update dictionary.
|
||||
|
||||
@@ -83,23 +114,6 @@ def merge_models(source: BaseModel, update_dict: dict[str, Any]) -> dict[str, An
|
||||
dict[str, Any]: Merged dictionary representing combined model data.
|
||||
"""
|
||||
|
||||
def deep_merge(source_data: Any, update_data: Any) -> Any:
|
||||
if isinstance(source_data, dict) and isinstance(update_data, dict):
|
||||
merged = dict(source_data)
|
||||
for key, update_value in update_data.items():
|
||||
if key in merged:
|
||||
merged[key] = deep_merge(merged[key], update_value)
|
||||
else:
|
||||
merged[key] = update_value
|
||||
return merged
|
||||
|
||||
# If both are lists, replace source list with update list
|
||||
if isinstance(source_data, list) and isinstance(update_data, list):
|
||||
return update_data
|
||||
|
||||
# For other types or if update_data is None, override source_data
|
||||
return update_data
|
||||
|
||||
source_dict = source.model_dump(
|
||||
exclude_unset=True,
|
||||
exclude_computed_fields=True,
|
||||
|
||||
Reference in New Issue
Block a user