From d1ca30c2ad66635c98c934be6ac9955cf3384a57 Mon Sep 17 00:00:00 2001 From: Daniel Dehennin Date: Thu, 26 Sep 2024 21:50:24 +0200 Subject: [PATCH] Fix incorrect override of minion node definition A pillars dict in a minion node definition was not overridding correctly the same dict in classes. * salt/utils/saltclass.py (expanded_dict_from_minion): do not pass a reference to minion dict or it will be overridden by classes during expansion. Fixes: #63933 --- changelog/63933.fixed.md | 4 ++++ salt/utils/saltclass.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/63933.fixed.md diff --git a/changelog/63933.fixed.md b/changelog/63933.fixed.md new file mode 100644 index 00000000000..794c170bd04 --- /dev/null +++ b/changelog/63933.fixed.md @@ -0,0 +1,4 @@ +Issue 63933: Fixes an issue with `saltclass.expanded_dict_from_minion` +function where it was passing a reference to minion `dict` which was +overridden by nested classes during class expansion. Copy the node +definition with `copy.deepcopy` instead of passing a reference. diff --git a/salt/utils/saltclass.py b/salt/utils/saltclass.py index 1f6df19d128..c18d01af3d1 100644 --- a/salt/utils/saltclass.py +++ b/salt/utils/saltclass.py @@ -1,3 +1,4 @@ +import copy import glob import logging import os @@ -362,7 +363,9 @@ def expanded_dict_from_minion(minion_id, salt_data): node_dict[minion_id] = {} # Merge newly found pillars into existing ones - dict_merge(salt_data["__pillar__"], node_dict[minion_id].get("pillars", {})) + dict_merge( + salt_data["__pillar__"], copy.deepcopy(node_dict[minion_id]).get("pillars", {}) + ) # Get 2 ordered lists: # expanded_classes: A list of all the dicts