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
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,16 @@ async def list_sessions(
s_state = data.get("state", {})
u_state = user_states_map.get(u_id, {})
merged = self._merge_state(app_state, u_state, s_state)
update_time = data.get("updateTime")
last_update_time = 0.0
if update_time:
if isinstance(update_time, datetime):
last_update_time = update_time.timestamp()
else:
try:
last_update_time = float(update_time)
except (ValueError, TypeError):
pass

sessions.append(
Session(
Expand All @@ -418,7 +428,7 @@ async def list_sessions(
user_id=data["userId"],
state=merged,
events=[],
last_update_time=0.0,
last_update_time=last_update_time,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ async def test_list_sessions_with_user_id(mock_firestore_client):
"appName": app_name,
"userId": user_id,
"state": {"session_key": "session_val"},
"updateTime": 1234567890.0,
}

app_state_coll = mock.MagicMock()
Expand Down Expand Up @@ -454,6 +455,7 @@ def collection_side_effect(name):
assert session.state["session_key"] == "session_val"
assert session.state["app:app_key"] == "app_val"
assert session.state["user:user_key"] == "user_val"
assert session.last_update_time == 1234567890.0


@pytest.mark.asyncio
Expand All @@ -467,6 +469,7 @@ async def test_list_sessions_without_user_id(mock_firestore_client):
"appName": app_name,
"userId": "user1",
"state": {"session_key": "session_val"},
"updateTime": 1234567890.0,
}

mock_firestore_client.collection_group.return_value.where.return_value.get = (
Expand Down Expand Up @@ -508,6 +511,7 @@ def collection_side_effect(name):
assert session.id == "session1"
assert session.state["app:app_key"] == "app_val"
assert session.state["user:user_key"] == "user_val"
assert session.last_update_time == 1234567890.0

mock_firestore_client.collection_group.assert_called_once_with("sessions")
mock_firestore_client.collection_group.return_value.where.assert_called_once_with(
Expand Down
Loading