Skip to content

fix: silent error handling and defensive improvements#2450

Open
AdrianBesleaga wants to merge 1 commit intoi-am-bee:mainfrom
AdrianBesleaga:main
Open

fix: silent error handling and defensive improvements#2450
AdrianBesleaga wants to merge 1 commit intoi-am-bee:mainfrom
AdrianBesleaga:main

Conversation

@AdrianBesleaga
Copy link

fix: silent error handling and defensive improvements

  • update_provider_env silently swallows errors when provider lookup fails (returnraise). Callers get no error on invalid provider_id — breaks error handling contract.
  • SDK _load_variables dirty detection tracks values not just keys (setdict). Value changes bypass reload logging and missing-env validation.
  • patch_provider uses is not None instead of or for optional watsonx fields. or prevents clearing fields to falsy values like empty string.

Added unit tests for all three fixes. All existing tests pass (12/12 SDK, 107/107 server).

…anges and removals, and fix provider patch logic to correctly handle `None` and empty string updates.
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 18, 2026
@gemini-code-assist
Copy link
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 introduces several critical fixes to improve error handling and data integrity within the system. It addresses issues where errors were silently swallowed, environment variable changes were not fully detected, and optional fields could not be properly cleared. These changes enhance the robustness and predictability of the application's behavior, particularly in how it manages provider configurations and environment variables.

Highlights

  • Error Propagation: The update_provider_env function now explicitly raises an EntityNotFoundError when a specified provider is not found, instead of silently failing.
  • SDK Variable Tracking: The SDK's _load_variables mechanism has been enhanced to track both keys and values of environment variables, ensuring that changes in variable values (not just their presence/absence) are correctly detected and reloaded.
  • Flexible Patching: The patch_provider function has been updated to use is not None checks for optional WatsonX fields and API keys, allowing these fields to be explicitly cleared or set to falsy values like empty strings.
  • Comprehensive Testing: New unit tests have been added across the SDK and server components to validate these fixes, covering scenarios for variable value changes, key removals, and correct error propagation.

🧠 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.

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

This pull request introduces several valuable fixes for silent error handling and defensive programming. The change to raise an exception instead of returning silently in update_provider_env improves error propagation. The modification in _load_variables to track environment variable values in addition to keys ensures that value changes are correctly detected. Finally, using is not None in patch_provider allows for clearing optional fields with falsy values. The inclusion of unit tests for all three fixes is excellent. I have one suggestion to improve code consistency.

Comment on lines +165 to +168
updated_provider.watsonx_project_id = watsonx_project_id if watsonx_project_id is not None else updated_provider.watsonx_project_id
updated_provider.watsonx_space_id = watsonx_space_id if watsonx_space_id is not None else updated_provider.watsonx_space_id

updated_api_key = api_key or old_api_key
updated_api_key = api_key if api_key is not None else old_api_key
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While these changes correctly use is not None for updating optional fields, there's a remaining inconsistency in this block. The updates for type and base_url still use the or operator, while name, description, and the fields you've updated now use the safer if ... is not None pattern. For consistency and to prevent potential future bugs, it would be best to apply the same pattern to type and base_url as well. While it may not be a bug now, standardizing on this safer pattern improves maintainability.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38b228b700

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +322 to 325
self._all_configured_variables.update(variables)

if dirty := old_variables != self._all_configured_variables:
logger.info(f"Environment variables reloaded dynamically: {self._all_configured_variables}")

Choose a reason for hiding this comment

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

P1 Badge Stop logging provider env values after dynamic reload

Because _all_configured_variables now stores the full {name: value} mapping, the existing logger.info(...) call emits every provider variable value on first load and whenever any variable changes. In the common case where provider variables include secrets such as API keys, this writes plaintext credentials into application logs; before this change only variable names were tracked. Please log only the keys (or a count) here.

Useful? React with 👍 / 👎.

Comment on lines +165 to +166
updated_provider.watsonx_project_id = watsonx_project_id if watsonx_project_id is not None else updated_provider.watsonx_project_id
updated_provider.watsonx_space_id = watsonx_space_id if watsonx_space_id is not None else updated_provider.watsonx_space_id

Choose a reason for hiding this comment

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

P2 Badge Revalidate WatsonX IDs before persisting empty strings

Switching these fields to is not None lets callers send "" to clear a WatsonX project/space ID, but updated_provider is mutated after model_copy() so ModelProvider.validate_watsonx_config() is never re-run. If a WatsonX provider is patched with watsonx_project_id="" and no replacement watsonx_space_id, uow.model_providers.update() will save an invalid row, and later reads fail when SqlAlchemyModelProviderRepository._row_to_model_provider() reconstructs the model. Normalizing empty strings back to None or revalidating before save would avoid bricking that provider.

Useful? React with 👍 / 👎.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant