Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/google/adk/sessions/database_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ async def get_session(

stmt = stmt.order_by(schema.StorageEvent.timestamp.desc())

if config and config.num_recent_events:
if config and config.num_recent_events is not None:
stmt = stmt.limit(config.num_recent_events)

result = await sql_session.execute(stmt)
Expand Down
7 changes: 7 additions & 0 deletions tests/unittests/sessions/test_session_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,13 @@ async def test_get_session_with_config(session_service):
events = session.events
assert len(events) == num_test_events

# num_recent_events=0 should return no events.
config = GetSessionConfig(num_recent_events=0)
session = await session_service.get_session(
app_name=app_name, user_id=user_id, session_id=session.id, config=config
)
assert len(session.events) == 0

# Only expect the most recent 3 events.
num_recent_events = 3
config = GetSessionConfig(num_recent_events=num_recent_events)
Expand Down