Skip to content

fix: resolve startup crash from test import leak and silent retry data loss in invoke()#43

Open
xemishra wants to merge 1 commit into
google:mainfrom
xemishra:fix/factory-test-import-and-connector-retry-logic
Open

fix: resolve startup crash from test import leak and silent retry data loss in invoke()#43
xemishra wants to merge 1 commit into
google:mainfrom
xemishra:fix/factory-test-import-and-connector-retry-logic

Conversation

@xemishra

@xemishra xemishra commented Jun 6, 2026

Copy link
Copy Markdown

Summary

This PR fixes two bugs: one that crashes the app before it opens, and one
that silently drops API data during retry attempts.

Bug 1 - Startup Crash: Test Mock Imported at Production Module Level

File: estimators/factory.py

MockUrlInvoker was imported unconditionally at the top of factory.py:

from tests.files.mocks import MockUrlInvoker

The tests/ package is not shipped in production installs or Docker images,
so this raises an ImportError the moment the app loads - before the window
even opens. No credentials are checked, no scan runs.

Fix: Deferred the import into get_mock_url_invoker() with a clear error
message explaining it is test-only. The factory now loads cleanly in all
environments.


Bug 2 - Silent Data Loss: Retry Logic Drops Requests in invoke()

File: util/connectors.py

Two issues in the invoke() retry loop:

  1. Wrong source list for rebuild. curr_batch was filtered from itself
    on each iteration rather than from the original batch. Once a request
    was filtered out (due to an ID type mismatch), it could never re-enter
    the retry queue even if retries remained.

  2. ID type mismatch. failed_response_ids was built as a plain list
    from response dicts whose "id" may be a string, while request["id"]
    is an int. The in check silently failed, so curr_batch became empty
    and all retries were skipped with no log warning.

  3. Broken f-string. The failure logger used nested quotes incompatible
    with Python < 3.12, causing a SyntaxError and swallowing the exception
    path entirely.

Fix: Rebuilt curr_batch from the original batch list, used a set
of str-cast IDs for reliable membership testing, and corrected the logger
to safely format response IDs.


Testing

  • Verified from estimators.factory import EstimatorFactory succeeds
    without the tests/ package present.
  • Verified from util.connectors import UrlInvoker parses cleanly on
    Python 3.10+.

Files Changed

  • estimators/factory.py
  • util/connectors.py

@google-cla

google-cla Bot commented Jun 6, 2026

Copy link
Copy Markdown

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.

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