Skip to content

Commit f45f453

Browse files
docs: Add doc to recursive merge, and uuid_utils to pyproject
1 parent 5c5dba7 commit f45f453

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

diracx-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies = [
2323
"pydantic-settings",
2424
"pyyaml",
2525
"sh",
26+
"uuid_utils"
2627
]
2728
dynamic = ["version"]
2829

diracx-core/src/diracx/core/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,26 @@ def extract_timestamp_from_uuid7(uuid_str: str) -> datetime:
287287

288288

289289
def recursive_dict_merge(x: T_DICTS, y: T_DICTS) -> T_DICTS:
290+
"""Used to merge two dictionaries with different types in it.
291+
292+
Use case: pilot secrets constraints that we update.
293+
"""
290294
result: dict[str, Any] = dict(x)
291295

292296
for k, v in y.items():
293297
if k in result:
294298
if isinstance(result[k], dict) and isinstance(v, dict):
299+
# If it's a dict, recursion
295300
result[k] = recursive_dict_merge(result[k], v)
296301
elif isinstance(result[k], list) and isinstance(v, list):
297-
result[k] = result[k] + v
302+
# Prevent duplicates (costy operation, but done no that many times)
303+
result[k] = list(set(result[k] + v))
304+
elif isinstance(result[k], set) and isinstance(v, set):
305+
# If it's a set, update values
306+
result[k].update(v)
298307
else:
308+
# Other types are: int, str, byte, float, bool
309+
# No need to handle it differently, just replace the value
299310
result[k] = v
300311
else:
301312
result[k] = v

0 commit comments

Comments
 (0)