Fix bug where -s could reset settings to defaults, closes #2389

This commit is contained in:
Simon Willison 2024-08-14 14:28:48 -07:00
commit bf953628bb
4 changed files with 70 additions and 1 deletions

View file

@ -25,6 +25,7 @@ from .utils import (
LoadExtension,
StartupError,
check_connection,
deep_dict_update,
find_spatialite,
parse_metadata,
ConnectionProblem,
@ -552,7 +553,9 @@ def serve(
# Merge in settings from -s/--setting
if settings:
settings_updates = pairs_to_nested_config(settings)
config_data.update(settings_updates)
# Merge recursively, to avoid over-writing nested values
# https://github.com/simonw/datasette/issues/2389
deep_dict_update(config_data, settings_updates)
kwargs = dict(
immutables=immutable,

View file

@ -1451,3 +1451,12 @@ async def calculate_etag(filepath, chunk_size=4096):
_etag_cache[filepath] = etag
return etag
def deep_dict_update(dict1, dict2):
for key, value in dict2.items():
if isinstance(value, dict):
dict1[key] = deep_dict_update(dict1.get(key, type(value)()), value)
else:
dict1[key] = value
return dict1