Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Comments

fix: Raise meaningful exception when oauth callback times out#363

Merged
parthea merged 7 commits intogoogleapis:mainfrom
mafrosis:handle-timeout
Feb 17, 2026
Merged

fix: Raise meaningful exception when oauth callback times out#363
parthea merged 7 commits intogoogleapis:mainfrom
mafrosis:handle-timeout

Conversation

@mafrosis
Copy link
Contributor

@mafrosis mafrosis commented Jul 8, 2024

I found that when timeout_seconds parameter is used, the code raises an exception such as:

  File "/usr/lib/python3.12/site-packages/google_auth_oauthlib/flow.py", line 520, in run_local_server
    authorization_response = wsgi_app.last_request_uri.replace("http", "https")
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'

This PR adds a custom exception such that a caller can handle this case.

I'm unable to run the full nox suite locally, but it looks like nothing has broken. I'll make any changes needed when the CI tests run.

@mafrosis mafrosis requested review from a team as code owners July 8, 2024 01:56
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Jul 8, 2024
@westarle westarle assigned arithmetic1728 and unassigned westarle Jul 8, 2024
@chalmerlowe chalmerlowe added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 17, 2026
Removing temporarily commented out code.
@chalmerlowe chalmerlowe added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Feb 17, 2026


class WSGITimeoutError(AttributeError):
"""Raised when the WSGI server times out waiting for a response."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to Reviewer:

Why did we subclass on 'AttributeError'?

'AttributeError' was historically the error that was raised if this line failed:

authorization_response = wsgi_app.last_request_uri.replace("http", "https")

and thus we want to minimize the possibility for a breaking change if customers have code such as the following present in their apps.

try:
    data = server_obj.attribute
except AttributeError:
    # Handle the missing value gracefully
    data = DEFAULT_VALUE

Because of Python’s exception hierarchy, any code catching AttributeError will also catch WSGITimeoutError.

Copy link
Contributor

@chalmerlowe chalmerlowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chalmerlowe chalmerlowe added the automerge Merge the pull request once unit tests and other checks pass. label Feb 17, 2026
@parthea parthea changed the title feat: Raise meaningful exception when oauth callback times out fix: Raise meaningful exception when oauth callback times out Feb 17, 2026
@parthea parthea enabled auto-merge (squash) February 17, 2026 17:50
@parthea parthea merged commit d77c874 into googleapis:main Feb 17, 2026
16 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Feb 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

kokoro:force-run Add this label to force Kokoro to re-run the tests. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants