-
Notifications
You must be signed in to change notification settings - Fork 799
Description
Context
In generic_config_updater/patch_sorter.py, the _get_value() helper function automatically converts any numeric-looking token into an integer:
@staticmethod
def _get_value(config, tokens):
for token in tokens:
if isinstance(token, str) and token.isnumeric():
token = int(token)
config = config[token]This causes incorrect behavior when the target config uses string keys that look like numbers.
Problem
When applying a patch such as:
[
{
"op": "replace",
"path": "/TC_TO_QUEUE_MAP/AZURE/8",
"value": "7"
},
{
"op": "add",
"path": "/TC_TO_QUEUE_MAP/AZURE/7",
"value": "6"
}
]The last token ("7" or "8") is converted into int, but in the actual config the keys are strings, not integers:
Target config contains: "7"
Patch attempts to look up: 7
This results in a KeyError or incorrect patch ordering behavior because config[7] does not exist while config["7"] does.
Expected Behavior
PatchSorter should respect the actual JSON structure and not guess key types. If the config contains string keys, patch processing must preserve string semantics and avoid coercing tokens to integers.
Impact
Patches on configs with numeric string keys fail to apply.
Patch sorting based on _get_value() becomes unreliable due to mismatched key types.
Affects real-world configs such as TC_TO_QUEUE_MAP, where queue indices are strings.
Proposed Directions
Remove automatic int() coercion.
Or infer key types from the actual config dict.
Or attempt both str and int lookups in a safe order.