Skip to content

Commit

Permalink
Fix apply to cope better with missing last_applied entries (#352)
Browse files Browse the repository at this point in the history
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'

Co-authored-by: Will Thames <will@thames.id.au>
  • Loading branch information
openshift-cherrypick-robot and willthames committed Feb 18, 2020
1 parent 169a112 commit 19a37a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openshift/dynamic/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ def get_delta(last_applied, actual, desired, position=None):
if actual_value is None:
patch[k] = desired_value
elif isinstance(desired_value, dict):
p = get_delta(last_applied.get(k), actual_value, desired_value, this_position)
p = get_delta(last_applied.get(k, {}), actual_value, desired_value, this_position)
if p:
patch[k] = p
elif isinstance(desired_value, list):
p = list_merge(last_applied.get(k), actual_value, desired_value, this_position)
p = list_merge(last_applied.get(k, []), actual_value, desired_value, this_position)
if p:
patch[k] = [item for item in p if item]
elif actual_value != desired_value:
Expand Down
31 changes: 31 additions & 0 deletions test/unit/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,37 @@
}
}
}
),
dict(
last_applied = {
'kind': 'MadeUp',
'toplevel': {
'original': 'entry'
}
},
actual = {
'kind': 'MadeUp',
'toplevel': {
'original': 'entry',
'another': {
'nested': {
'entry': 'value'
}
}
}
},
desired = {
'kind': 'MadeUp',
'toplevel': {
'original': 'entry',
'another': {
'nested': {
'entry': 'value'
}
}
}
},
expected = {}
)
]

Expand Down

0 comments on commit 19a37a6

Please sign in to comment.