Skip to content

Commit 70de36b

Browse files
committed
Don't call get on context if not a dict
With ironic we have a case where context is a RequestContext but this context object doesn't have the original_resources attribute. In this case we're proceeding into else, call get() on context, which RequestContext does not have either and run into AttributeError: 'RequestContext' object has no attribute 'get' To guard against this we're now only calling get() on context if it explicitly is a dict. If none can be found we just don't have any original_resources. The only case where this logic will break is if we have cases where we have a context object that doesn't have a original_resources attribute, is not a dict but SOMEHOW provides a get() method that would provide the original_resources when provided as a string argument (which I don't think is very likely).
1 parent f47e429 commit 70de36b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

auditmiddleware/_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def _create_cadf_event(self, project, res_spec, res_id, res_parent_id,
543543
original_resources = []
544544
if hasattr(context, 'original_resources'):
545545
original_resources = context.original_resources
546-
else:
546+
elif isinstance(context, dict):
547547
original_resources = context.get('original_resources', [])
548548

549549
# If we found original_resources and it's a list, get project_id

0 commit comments

Comments
 (0)