mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: disallow setting non-existent properties in BigQuery tools and credentials config
This will save the agent builder getting wrong impression if by mistake they set a property that does not exist. PiperOrigin-RevId: 803208559
This commit is contained in:
committed by
Copybara-Service
parent
ebf2c98e41
commit
45c1fcc84f
@@ -26,6 +26,7 @@ from google.auth.exceptions import RefreshError
|
||||
from google.auth.transport.requests import Request
|
||||
import google.oauth2.credentials
|
||||
from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import model_validator
|
||||
|
||||
from ..auth.auth_credential import AuthCredential
|
||||
@@ -44,8 +45,7 @@ class BaseGoogleCredentialsConfig(BaseModel):
|
||||
"""
|
||||
|
||||
# Configure the model to allow arbitrary types like Credentials
|
||||
model_config = {"arbitrary_types_allowed": True}
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True, extra="forbid")
|
||||
credentials: Optional[google.auth.credentials.Credentials] = None
|
||||
"""The existing auth credentials to use. If set, this credential will be used
|
||||
for every end user, end users don't need to be involved in the oauthflow. This
|
||||
|
||||
@@ -18,6 +18,7 @@ from enum import Enum
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic import ConfigDict
|
||||
from pydantic import field_validator
|
||||
|
||||
from ...utils.feature_decorator import experimental
|
||||
@@ -50,6 +51,9 @@ class WriteMode(Enum):
|
||||
class BigQueryToolConfig(BaseModel):
|
||||
"""Configuration for BigQuery tools."""
|
||||
|
||||
# Forbid any fields not defined in the model
|
||||
model_config = ConfigDict(extra='forbid')
|
||||
|
||||
write_mode: WriteMode = WriteMode.BLOCKED
|
||||
"""Write mode for BigQuery tools.
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from google.adk.tools.bigquery.bigquery_credentials import BigQueryCredentialsConfig
|
||||
from google.adk.tools.bigquery import BigQueryCredentialsConfig
|
||||
# Mock the Google OAuth and API dependencies
|
||||
import google.auth.credentials
|
||||
import google.oauth2.credentials
|
||||
@@ -171,3 +171,12 @@ class TestBigQueryCredentials:
|
||||
),
|
||||
):
|
||||
BigQueryCredentialsConfig()
|
||||
|
||||
def test_invalid_property_raises_error(self):
|
||||
"""Test BigQueryCredentialsConfig raises exception when setting invalid property."""
|
||||
with pytest.raises(ValueError):
|
||||
BigQueryCredentialsConfig(
|
||||
client_id="test_client_id",
|
||||
client_secret="test_client_secret",
|
||||
non_existent_field="some value",
|
||||
)
|
||||
|
||||
@@ -27,8 +27,16 @@ def test_bigquery_tool_config_experimental_warning():
|
||||
BigQueryToolConfig()
|
||||
|
||||
|
||||
def test_bigquery_tool_config_invalid_property():
|
||||
"""Test BigQueryToolConfig raises exception when setting invalid property."""
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
):
|
||||
BigQueryToolConfig(non_existent_field="some value")
|
||||
|
||||
|
||||
def test_bigquery_tool_config_invalid_application_name():
|
||||
"""Test BigQueryToolConfig with invalid application name."""
|
||||
"""Test BigQueryToolConfig raises exception with invalid application name."""
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="Application name should not contain spaces.",
|
||||
|
||||
Reference in New Issue
Block a user