Jinja possibility to ignore undefined error or respond with None or similar

Hi,

I have several workflows using jinja expressions looping through objects or just get a single value. These objects do not always look the same and sometimes part of these objects are not available at all. In this case the workflow fails as it can not catch a specific value. I can fix it by using several if statements to check if something is available but it is really annoying if we talk about nested dicts.

e.g.

{{ ctx().search_result.alert_type_details.detail.srcipv4 }} 

Sometimes there is no section “detail”. Then I get the error:

UndefinedError: 'dict object' has no attribute 'detail'"

even

{{ ctx().search_result.alert_type_details.detail.srcipv4 | default('None ') }} 

is not working as this would only work if srcipv4 is missing.

In another case maybe the whole “alert_type_details” section is not there, therefore it is really annoying to catch this errors using if statements or multiple default tests.

Is there a handy possibility to ignore these Undifined errors and instead respond with None, an empty string, dict, … whatever?

Thanks.

Nikolas