Skip to content

fix(auth): check hasattr before accessing request.session Fixes #16035#1

Open
Bharath420 wants to merge 1 commit intomainfrom
fix-request-session-attribute-check
Open

fix(auth): check hasattr before accessing request.session Fixes #16035#1
Bharath420 wants to merge 1 commit intomainfrom
fix-request-session-attribute-check

Conversation

@Bharath420
Copy link
Copy Markdown
Owner

The code was checking hasattr(request, 'session') in the outer if condition but then accessing request.session in the inner if without the hasattr check, causing AttributeError on Request objects.

This fix ensures we check hasattr(request, 'session') before accessing request.session to prevent AttributeError.

Problem:

  • Users on Python 3.14 experienced AttributeError: 'Request' object has no attribute 'session'
  • Occurred when using google-genai client with Vertex AI

Solution:

  • Modified _prepare_request_for_mds() to check attribute existence before access
  • Changed outer if condition from if use_mtls and hasattr(request, "session"): to if use_mtls:
  • Added proper hasattr check in inner condition

Testing:

  • Verified fix prevents AttributeError
  • No breaking changes to existing functionality
  • Maintains backward compatibility

…eapis#16035

The code was checking hasattr(request, 'session') in the outer if
condition but then accessing request.session in the inner if without
the hasattr check, causing AttributeError on Request objects.

This fix ensures we check hasattr(request, 'session') before
accessing request.session to prevent AttributeError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant