Skip to content

Commit

Permalink
fix returning None from FindInMap (#3866)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Dec 10, 2024
1 parent 30ecbc1 commit b1ddd33
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cfnlint/template/transforms/_language_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,12 @@ def value(

if mapping:
try:
return mapping.get(t_map[1].value(cfn, params, only_params), {}).get(
value = mapping.get(t_map[1].value(cfn, params, only_params), {}).get(
t_map[2].value(cfn, params, only_params)
)
if value is None:
raise _ResolveError("Can't resolve Fn::FindInMap", self._obj)
return value
except _ResolveError as e:
if len(self._map) == 4 and default_on_resolver_failure:
return self._map[3].value(cfn, params, only_params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ def test_find_in_map_values_with_default(self):
with self.assertRaises(_ResolveError):
map.value(self.cfn, None, False, False)

def test_find_in_map_values_not_found_with_default(self):
map = _ForEachValueFnFindInMap(
"a", ["Bucket", "Production", "DNE", {"DefaultValue": "bar"}]
)

self.assertEqual(map.value(self.cfn, None, False, True), "bar")
self.assertEqual(map.value(self.cfn, None, False, False), ["foo", "bar"])

def test_find_in_map_values_without_default(self):
map = _ForEachValueFnFindInMap("a", ["Bucket", {"Ref": "Foo"}, "Key"])

Expand Down

0 comments on commit b1ddd33

Please sign in to comment.