mlflow/mlflow · warning · ValueError
The two merging dictionaries contains duplicate keys: {dupli
Error message
The two merging dictionaries contains duplicate keys: {duplicate_keys}. What it means
mlflow.utils.merge_dicts merges two dicts but, when raise_on_duplicates=True (the default), refuses to silently overwrite keys present in both inputs. It raises ValueError listing the duplicate keys so data loss is explicit.
Source
Thrown at mlflow/utils/__init__.py:132
return truncated
def merge_dicts(dict_a, dict_b, raise_on_duplicates=True):
"""This function takes two dictionaries and returns one singular merged dictionary.
Args:
dict_a: The first dictionary.
dict_b: The second dictionary.
raise_on_duplicates: If True, the function raises ValueError if there are duplicate keys.
Otherwise, duplicate keys in `dict_b` will override the ones in `dict_a`.
Returns:
A merged dictionary.
"""
duplicate_keys = dict_a.keys() & dict_b.keys()
if raise_on_duplicates and len(duplicate_keys) > 0:
raise ValueError(f"The two merging dictionaries contains duplicate keys: {duplicate_keys}.")
return dict_a | dict_b
def _get_fully_qualified_class_name(obj):
"""
Obtains the fully qualified class name of the given object.
"""
return obj.__class__.__module__ + "." + obj.__class__.__name__
def _inspect_original_var_name(var, fallback_name):
"""
Inspect variable name, will search above frames and fetch the same instance variable name
in the most outer frame.
If inspect failed, return fallback_name
"""
if var is None:
return fallback_nameView on GitHub (pinned to 6a27f2decc)
Solutions
- Remove the duplicate keys from one dict before merging
- Pass raise_on_duplicates=False if last-wins (dict_b) overwrite is acceptable
- Rename keys to make them unique before merging
Example fix
// before merged = merge_dicts(defaults, user_cfg) # KeyError-free but ValueError on dup keys // after merged = merge_dicts(defaults, user_cfg, raise_on_duplicates=False) # or de-duplicate user_cfg first
Defensive patterns
Strategy: try-catch
Validate before calling
dups = dict_a.keys() & dict_b.keys()
if dups:
print(f"Duplicate keys will raise: {dups}") Try / catch
try:
merged = merge_dicts(dict_a, dict_b)
except ValueError as e:
# decide policy: last-wins merge
merged = {**dict_a, **dict_b} Prevention
- De-duplicate config sources before merging
- Pass raise_on_duplicates=False deliberately when overwrite is intended
- Log duplicate keys in config pipelines
When it happens
Trigger: Calling merge_dicts(dict_a, dict_b) where the dicts share one or more keys, e.g. merging two params/config dicts built from overlapping sources; also directly in tests.
Common situations: Merging default and user config that share keys; combining run params from two runs with overlapping names; environment-derived dicts colliding with defaults.
Related errors
- Must specify at least either `max_key_length` or `max_value_
- Cannot resolve {raw_source} as an evaluation dataset ID
- Template must be a list of dicts with role and content
- Use _BooleanEnvironmentVariable instead for boolean variable
- Failed to convert {val!r} for {self.name}: {e}
AI-assisted analysis of mlflow/mlflow@6a27f2decc (2026-08-29).
Data as JSON: /api/errors/2c300568b30c6660.
Report an issue: GitHub.