Skip to content

[DataStore] fix bare except clause in openai_provider async batch invoke - #9861

Open
qubeena07 wants to merge 1 commit into
mlrun:developmentfrom
qubeena07:fix/bare-except-openai-provider
Open

[DataStore] fix bare except clause in openai_provider async batch invoke#9861
qubeena07 wants to merge 1 commit into
mlrun:developmentfrom
qubeena07:fix/bare-except-openai-provider

Conversation

@qubeena07

Copy link
Copy Markdown

Summary

Fixes #9860

In mlrun/datastore/model_provider/openai_provider.py the async batch invoke method used a bare except: clause to catch exceptions during asyncio.gather() so it could cancel sibling tasks before re-raising.

A bare except: is a Python anti-pattern (Ruff E722) because it catches BaseException implicitly, making the intent of the code unclear. More importantly, in Python 3.8 and above asyncio.CancelledError is a subclass of BaseException not Exception, so changing to except Exception: would silently break the cancellation cleanup path.

The correct fix is except BaseException: which is explicit, preserves exactly the same behavior, and satisfies Ruff E722.

Changes:

  • One line change in mlrun/datastore/model_provider/openai_provider.py from bare except: to except BaseException:

Test plan

  • Verify existing async batch invoke behavior is unchanged
  • Confirm Ruff linting passes on the changed file
  • Verify that cancellation of the outer coroutine still properly cancels sibling tasks

Using a bare except clause catches BaseException implicitly which is
a Python anti-pattern flagged by Ruff E722. The intent here is to
cancel sibling tasks on any failure including asyncio.CancelledError
which is a BaseException subclass in Python 3.8 and above. Changed
to explicit except BaseException to preserve the same behavior while
making the intent clear.

Fixes mlrun#9860

Co-Authored-By: Dipika Ranabhat <qubeena7@gmail.com>

@liranbg liranbg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your first contribution @qubeena07! :)

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Smoke Tests with the PR synced to development HEAD 99ec9181: Pass

@github-actions

Copy link
Copy Markdown
Contributor

📊 Diff Coverage Report

📂 Click to view full coverage details

Diff Coverage

Diff: origin/development...HEAD, staged and unstaged changes

  • mlrun/datastore/model_provider/openai_provider.py (100%)

Summary

  • Total: 1 line
  • Missing: 0 lines
  • Coverage: 100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bare except clause in openai_provider async gather swallows BaseException signals

2 participants