Skip to content

fix(python): Add timeout to ErrorDocHelper requests.get() calls#1661

Open
maxlillo wants to merge 1 commit intolooker-open-source:mainfrom
maxlillo:fix/error-doc-helper-timeout
Open

fix(python): Add timeout to ErrorDocHelper requests.get() calls#1661
maxlillo wants to merge 1 commit intolooker-open-source:mainfrom
maxlillo:fix/error-doc-helper-timeout

Conversation

@maxlillo
Copy link
Copy Markdown

Summary

  • Add configurable timeout parameter (default 10 seconds) to requests.get() calls in ErrorDocHelper
  • Prevents Python scripts from hanging indefinitely when the error documentation CDN is unresponsive

Problem

The requests.get() calls in python/looker_sdk/error.py had no timeout parameter. When an API error occurs and the SDK attempts to fetch supplemental error documentation from https://static-a.cdn.looker.app/errorcodes/, if the CDN is reachable but unresponsive, the request blocks indefinitely.

This causes Python scripts using the SDK to hang when they encounter an API error and the CDN doesn't respond.

Changes

Added timeout parameter to:

  • get_index()
  • lookup()
  • parse_and_lookup()

All default to 10 seconds, which is consistent with common timeout practices for HTTP requests.

Test plan

  • Verify existing error handling behavior is unchanged when CDN is responsive
  • Verify requests fail gracefully within timeout when CDN is unresponsive

🤖 Generated with Claude Code

The requests.get() calls in ErrorDocHelper had no timeout parameter,
which could cause Python scripts using the SDK to hang indefinitely
when an API error occurs and the error documentation CDN is unresponsive.

This adds a configurable timeout parameter (default 10 seconds) to:
- get_index()
- lookup()
- parse_and_lookup()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@maxlillo maxlillo requested a review from a team as a code owner March 18, 2026 20:07
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the SDK's error handling by addressing a critical vulnerability where the application could become unresponsive if the error documentation CDN failed to respond. By introducing a default 10-second timeout to all network requests made for error documentation, the system is now designed to fail gracefully, preventing indefinite blocking and improving overall application stability.

Highlights

  • Timeout Parameter Added: A configurable timeout parameter, defaulting to 10 seconds, was added to all requests.get() calls within the ErrorDocHelper class.
  • Prevents Indefinite Hanging: This change prevents Python scripts from hanging indefinitely when the error documentation CDN is reachable but unresponsive, ensuring graceful failure.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds a timeout parameter to requests.get() calls in ErrorDocHelper, which is an important step to prevent the application from hanging when the error documentation CDN is unresponsive. My review includes a couple of suggestions to further improve the robustness of these network requests by adding checks for unsuccessful HTTP responses. This will ensure that errors like 404s or 500s are also handled gracefully.

Comment on lines +107 to 108
r = requests.get(f"{url}index.json", timeout=timeout)
self.lookup_dict = json.loads(r.text)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The requests.get() call doesn't check for unsuccessful HTTP status codes. If the server returns an error (e.g., 404, 500), r.text might not be valid JSON, which could lead to a json.JSONDecodeError. It's a good practice to handle such responses explicitly.

I suggest using r.raise_for_status() to raise an HTTPError for bad responses. This exception is a subclass of requests.exceptions.RequestException and will be caught by the handler in parse_and_lookup, ensuring graceful failure. Using r.json() is also more idiomatic for parsing JSON responses.

Suggested change
r = requests.get(f"{url}index.json", timeout=timeout)
self.lookup_dict = json.loads(r.text)
r = requests.get(f"{url}index.json", timeout=timeout)
r.raise_for_status()
self.lookup_dict = r.json()

Comment on lines +131 to 132
r = requests.get(f"{self.ERROR_CODES_URL}{error_doc_url}", timeout=timeout)
error_doc = r.text
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the other requests.get() call, this one doesn't handle non-200 HTTP status codes. If the request fails, r.text could contain an error message (e.g., an HTML page) instead of the expected markdown documentation. To make this more robust, it's best to check the response status.

Adding r.raise_for_status() will ensure the request was successful before its content is used. The resulting exception will be handled gracefully by the try...except block in parse_and_lookup.

Suggested change
r = requests.get(f"{self.ERROR_CODES_URL}{error_doc_url}", timeout=timeout)
error_doc = r.text
r = requests.get(f"{self.ERROR_CODES_URL}{error_doc_url}", timeout=timeout)
r.raise_for_status()
error_doc = r.text

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