Skip to content

fix: raise ValueError when sessionId and userId are incorrect combination(#1653) #1655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/google/adk/sessions/vertex_ai_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ async def get_session(
)
get_session_api_response = _convert_api_response(get_session_api_response)

if get_session_api_response["userId"] != user_id:
raise ValueError(f'Session not found: {session_id}')

session_id = get_session_api_response['name'].split('/')[-1]
update_timestamp = isoparse(
get_session_api_response['updateTime']
).timestamp()
session = Session(
app_name=str(app_name),
user_id=str(user_id),
user_id=str(get_session_api_response["userId"]),
id=str(session_id),
state=get_session_api_response.get('sessionState', {}),
last_update_time=update_timestamp,
Expand Down
14 changes: 14 additions & 0 deletions tests/unittests/sessions/test_vertex_ai_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ async def test_get_empty_session(agent_engine_id):
)
assert str(excinfo.value) == 'Session not found: 0'

@pytest.mark.asyncio
@pytest.mark.usefixtures('mock_get_api_client')
@pytest.mark.parametrize('agent_engine_id', [None, '123'])
async def test_get_another_user_session(agent_engine_id):
if agent_engine_id:
session_service = mock_vertex_ai_session_service(agent_engine_id)
else:
session_service = mock_vertex_ai_session_service()
with pytest.raises(ValueError) as excinfo:
await session_service.get_session(
app_name='123', user_id='user2', session_id='1'
)
assert str(excinfo.value) == 'Session not found: 1'


@pytest.mark.asyncio
@pytest.mark.usefixtures('mock_get_api_client')
Expand Down
Loading