Skip to content

Commit

Permalink
Remove unnecessary project_id == creds_id check for vertex (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle authored Feb 6, 2025
1 parent 22eef2d commit 35b6470
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 29 deletions.
5 changes: 0 additions & 5 deletions pydantic_ai_slim/pydantic_ai/models/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ async def ainit(self) -> None:
raise UserError(f'No project_id provided and none found in {creds_source}')
project_id = creds_project_id
else:
if creds_project_id is not None and self.project_id != creds_project_id:
raise UserError(
f'The project_id you provided does not match the one from {creds_source}: '
f'{self.project_id!r} != {creds_project_id!r}'
)
project_id = self.project_id

self._url = self.url_template.format(
Expand Down
24 changes: 0 additions & 24 deletions tests/models/test_vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,30 +92,6 @@ async def test_init_right_project_id(tmp_path: Path, allow_model_requests: None)
assert model.auth is not None


async def test_init_service_account_wrong_project_id(tmp_path: Path, allow_model_requests: None):
service_account_path = tmp_path / 'service_account.json'
save_service_account(service_account_path, 'my-project-id')

model = VertexAIModel('gemini-1.5-flash', service_account_file=service_account_path, project_id='different')

with pytest.raises(UserError) as exc_info:
await model.ainit()
assert str(exc_info.value) == snapshot(
"The project_id you provided does not match the one from service account file: 'different' != 'my-project-id'"
)


async def test_init_env_wrong_project_id(mocker: MockerFixture, allow_model_requests: None):
mocker.patch('pydantic_ai.models.vertexai.google.auth.default', return_value=(NoOpCredentials(), 'my-project-id'))
model = VertexAIModel('gemini-1.5-flash', project_id='different')

with pytest.raises(UserError) as exc_info:
await model.ainit()
assert str(exc_info.value) == snapshot(
"The project_id you provided does not match the one from `google.auth.default()`: 'different' != 'my-project-id'"
)


async def test_init_env_no_project_id(mocker: MockerFixture, allow_model_requests: None):
mocker.patch(
'pydantic_ai.models.vertexai.google.auth.default',
Expand Down

0 comments on commit 35b6470

Please sign in to comment.