Skip to content

Commit e62e15e

Browse files
czn574775237copybara-github
authored andcommitted
fix: sqlalchemy query error in DatabaseSessionService when using custom GetSessionConfig with PostgreSQL
Copybara import of the project: -- cec6f50 by ZhiNing <[email protected]>: COPYBARA_INTEGRATE_REVIEW=#705 from czn574775237:fix/issue-655 c15f116 PiperOrigin-RevId: 759381068
1 parent a786f75 commit e62e15e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/google/adk/sessions/database_session_service.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import copy
15-
from datetime import datetime
15+
from datetime import datetime, timezone
1616
import json
1717
import logging
1818
from typing import Any, Optional
@@ -374,17 +374,19 @@ async def get_session(
374374
)
375375
if storage_session is None:
376376
return None
377+
378+
if config and config.after_timestamp:
379+
after_dt = datetime.fromtimestamp(config.after_timestamp, tz=timezone.utc)
380+
timestamp_filter = StorageEvent.timestamp > after_dt
381+
else:
382+
timestamp_filter = True
377383

378384
storage_events = (
379-
sessionFactory.query(StorageEvent)
385+
sessionFactory.query(StorageEvent)
380386
.filter(StorageEvent.session_id == storage_session.id)
381-
.filter(
382-
StorageEvent.timestamp < config.after_timestamp
383-
if config
384-
else True
385-
)
386-
.limit(config.num_recent_events if config else None)
387+
.filter(timestamp_filter)
387388
.order_by(StorageEvent.timestamp.asc())
389+
.limit(config.num_recent_events if config and config.num_recent_events else None)
388390
.all()
389391
)
390392

0 commit comments

Comments
 (0)