Skip to content

Commit 3ec51ae

Browse files
willthamesfabianvf
authored andcommitted
Fix apply to cope better with missing last_applied entries (#351)
If desired and actual contain a dict structure that is missing from last_applied, continue rather than crashing with AttributeError: 'NoneType' object has no attribute 'get'
1 parent 29851d0 commit 3ec51ae

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

openshift/dynamic/apply.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ def get_delta(last_applied, actual, desired, position=None):
207207
if actual_value is None:
208208
patch[k] = desired_value
209209
elif isinstance(desired_value, dict):
210-
p = get_delta(last_applied.get(k), actual_value, desired_value, this_position)
210+
p = get_delta(last_applied.get(k, {}), actual_value, desired_value, this_position)
211211
if p:
212212
patch[k] = p
213213
elif isinstance(desired_value, list):
214-
p = list_merge(last_applied.get(k), actual_value, desired_value, this_position)
214+
p = list_merge(last_applied.get(k, []), actual_value, desired_value, this_position)
215215
if p:
216216
patch[k] = [item for item in p if item]
217217
elif actual_value != desired_value:

test/unit/test_apply.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,37 @@
283283
}
284284
}
285285
}
286+
),
287+
dict(
288+
last_applied = {
289+
'kind': 'MadeUp',
290+
'toplevel': {
291+
'original': 'entry'
292+
}
293+
},
294+
actual = {
295+
'kind': 'MadeUp',
296+
'toplevel': {
297+
'original': 'entry',
298+
'another': {
299+
'nested': {
300+
'entry': 'value'
301+
}
302+
}
303+
}
304+
},
305+
desired = {
306+
'kind': 'MadeUp',
307+
'toplevel': {
308+
'original': 'entry',
309+
'another': {
310+
'nested': {
311+
'entry': 'value'
312+
}
313+
}
314+
}
315+
},
316+
expected = {}
286317
)
287318
]
288319

0 commit comments

Comments
 (0)