Skip to content

Commit 3621936

Browse files
committed
Fix project_id handling for RequestContext objects
1 parent bf61780 commit 3621936

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

auditmiddleware/_api.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,25 @@ def _create_cadf_event(self, project, res_spec, res_id, res_parent_id,
520520
if not action:
521521
return None
522522

523+
# Try to get project_id from request headers
523524
project_id = request.environ.get('HTTP_X_PROJECT_ID')
524-
# If project_id is undefined, look for another variable. This is
525-
# added specific to catching delete events from Neutron
525+
526+
# If no project_id found, try to get it from the request context
526527
if project_id is None:
528+
# Get the adhoc attributes from the request environment
527529
adhoc_attrs = request.environ.get('webob.adhoc_attrs', {})
528-
context = adhoc_attrs.get('context', {})
529-
original_resources = context.get('original_resources', [])
530+
531+
# Get the context - could be dict or RequestContext object
532+
context = adhoc_attrs.get('context')
533+
534+
# Handle both dict and RequestContext object types
535+
original_resources = None
536+
if isinstance(context, dict):
537+
original_resources = context.get('original_resources', [])
538+
elif hasattr(context, 'original_resources'):
539+
original_resources = context.original_resources
540+
541+
# If we found original_resources and it's a list, get project_id
530542
if original_resources and isinstance(original_resources, list):
531543
first_resource = original_resources[0]
532544
if isinstance(first_resource, dict):

0 commit comments

Comments
 (0)