Skip to content

Fix DC API wrapper retry attempt counting (raise after final attempt)#1862

Open
rohitkumarbhagat wants to merge 3 commits intodatacommonsorg:masterfrom
rohitkumarbhagat:dc-api-wrapper-retry-fix
Open

Fix DC API wrapper retry attempt counting (raise after final attempt)#1862
rohitkumarbhagat wants to merge 3 commits intodatacommonsorg:masterfrom
rohitkumarbhagat:dc-api-wrapper-retry-fix

Conversation

@rohitkumarbhagat
Copy link
Contributor

This PR fixes the retry/attempt logic in util/dc_api_wrapper.py so retryable DC API failures (e.g. 429/5xx/timeouts) stop retrying after the configured maximum attempts and surface the underlying exception instead of silently falling through and returning None.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rohitkumarbhagat, 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 refines the retry mechanism within the DataCommons API wrapper. The primary goal is to ensure that API calls facing transient errors (like rate limits or server errors) adhere strictly to the configured maximum number of retry attempts. It also guarantees that once these attempts are exhausted, the original exception is raised, preventing silent failures and providing clearer feedback on API issues.

Highlights

  • Retry Logic Correction: The pull request fixes the retry/attempt logic in util/dc_api_wrapper.py to ensure that retryable DataCommons API failures (e.g., 429, 5xx, timeouts) correctly stop retrying after the configured maximum attempts.
  • Exception Propagation: Instead of silently falling through and returning None after failed attempts, the underlying exception is now surfaced, improving error handling and visibility.
  • Parameter Clarity: The retries parameter's docstring has been updated to clarify that it represents the 'Maximum number of attempts (including the first attempt)'.
  • New Unit Tests: New tests have been added in util/dc_api_wrapper_test.py to specifically verify that the wrapper correctly handles maximum retry attempts and stops retrying upon success.
Changelog
  • util/dc_api_wrapper.py
    • Updated the docstring for the retries parameter to clarify its meaning as 'Maximum number of attempts (including the first attempt)'.
    • Renamed the internal retries variable to max_attempts for improved readability and accuracy.
    • Modified the retry loop to iterate correctly from 1 to max_attempts + 1 to reflect the total number of attempts.
    • Adjusted logging messages to display the current attempt number and the total maximum attempts.
    • Updated calls to _should_retry_status_code to use the new max_attempts variable.
    • Corrected a logging message in _should_retry_status_code from 'retries' to 'attempts'.
  • util/dc_api_wrapper_test.py
    • Imported the mock module from unittest for testing purposes.
    • Imported DCConnectionError for specific exception handling tests.
    • Added test_dc_api_wrapper_attempts_no_extra_retries to verify that the wrapper does not exceed the specified maximum attempts and raises the appropriate exception.
    • Added test_dc_api_wrapper_stops_after_success to confirm that the wrapper ceases retrying immediately after a successful API response.
Activity
  • The pull request was created by rohitkumarbhagat.
  • The core change addresses a bug in the retry logic of the DataCommons API wrapper.
  • The changes involve modifying the dc_api_wrapper.py file to correctly count retry attempts and ensure exceptions are raised after the final attempt.
  • New unit tests have been introduced in dc_api_wrapper_test.py to validate the corrected retry behavior, covering scenarios for maximum attempts and early success.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@rohitkumarbhagat rohitkumarbhagat enabled auto-merge (squash) February 4, 2026 09:54
Copy link
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

The pull request refactors the retry mechanism in dc_api_wrapper.py to use max_attempts instead of retries, clarifying that the count includes the initial attempt. This change is consistently applied across the function's logic and logging. Additionally, new unit tests have been added to dc_api_wrapper_test.py to validate the updated retry behavior, ensuring that the API wrapper correctly handles the specified number of attempts and stops retrying upon successful execution. The changes improve the clarity and robustness of the retry logic.

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