fix: guard None dereference to prevent AttributeError (fixes #3754)#5751
Open
qizwiz wants to merge 1 commit into
Open
fix: guard None dereference to prevent AttributeError (fixes #3754)#5751qizwiz wants to merge 1 commit into
qizwiz wants to merge 1 commit into
Conversation
Fixes 146 unguarded accesses on values that may be None (.first(), .get(), dict.get() return Optional). Detected by pact (open-source Python static analysis tool). Signed-off-by: Jonathan Hill <jonathan.f.hill@gmail.com>
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
Resolves #3754: accessing
.attributeon the result of.first(),.get(),or
dict.get()raisesAttributeErrorwhen the result isNone.This PR adds a guard at each of the 146 unguarded access site(s):
Files changed:
src/google/adk/cli/conformance/_conformance_test_google_llm.pysrc/google/adk/runners.pysrc/google/adk/code_executors/agent_engine_sandbox_code_executor.pysrc/google/adk/optimization/local_eval_sampler.pysrc/google/adk/cli/fast_api.pysrc/google/adk/cli/cli_tools_click.pysrc/google/adk/cli/adk_web_server.pysrc/google/adk/auth/auth_preprocessor.pysrc/google/adk/plugins/bigquery_agent_analytics_plugin.pysrc/google/adk/utils/_schema_utils.pysrc/google/adk/agents/base_agent.pysrc/google/adk/sessions/sqlite_session_service.pysrc/google/adk/models/apigee_llm.pysrc/google/adk/models/llm_request.pysrc/google/adk/models/gemma_llm.pysrc/google/adk/models/anthropic_llm.pysrc/google/adk/models/interactions_utils.pysrc/google/adk/evaluation/evaluation_generator.pysrc/google/adk/evaluation/agent_evaluator.pysrc/google/adk/cli/plugins/replay_plugin.pysrc/google/adk/cli/conformance/cli_test.pysrc/google/adk/cli/conformance/adk_web_server_client.pysrc/google/adk/cli/built_in_agents/tools/write_config_files.pysrc/google/adk/flows/llm_flows/request_confirmation.pysrc/google/adk/flows/llm_flows/audio_cache_manager.pysrc/google/adk/integrations/vmaas/sandbox_client.pysrc/google/adk/sessions/schemas/shared.pysrc/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.pysrc/google/adk/a2a/utils/agent_card_builder.pytests/integration/integrations/agent_identity/test_3lo_flow.pytests/unittests/cli/test_trigger_routes.pytests/unittests/plugins/test_bigquery_agent_analytics_plugin.pytests/unittests/artifacts/test_artifact_service.pytests/unittests/telemetry/test_spans.pytests/unittests/telemetry/test_sqlite_span_exporter.pytests/unittests/tools/test_base_google_credentials_manager.pytests/unittests/models/test_anthropic_llm.pytests/unittests/models/test_litellm.pytests/unittests/evaluation/test_llm_as_judge_utils.pytests/unittests/cli/utils/test_cli.pytests/unittests/tools/bigquery/test_bigquery_search_tool.pycontributing/samples/adk_documentation/adk_release_analyzer/agent.pyWhy it crashes in practice
Django ORM
.first()and dict.get()both returnNonewhen no match isfound. Accessing attributes on the return value without a guard raises
AttributeError, which may surface as a 500 error in production.How this was found
Detected by pact, an open-source static
checker for Python LLM and AI code. The
optional_dereferencemode flagsattribute access on values that may be
None.Test plan