Skip to content

Error when calling DatabaseSessionService.get_session() with config parameter #602

@polaris340

Description

@polaris340

** Please make sure you read the contribution guide and file the issues in the rigth place. **
Contribution guide.

Describe the bug
When you call DatabaseSessionService.get_session() with the config parameter, it raises different errors depending on the config values provided.

  1. after_timestamp=None
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Only '=', '!=', 'is_()', 'is_not()', 'is_distinct_from()', 'is_not_distinct_from()' operators can be used with None/True/False
  1. Passing a numeric value to after_timestamp (num_recent_events=None)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) operator does not exist: timestamp without time zone < numeric
LINE 3: ...4fbd-46ac-8bb4-0ff6e761e916' AND events.timestamp < 10.0 ORD...
                                                             ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
  1. Providing both after_timestamp, num_recent_events
sqlalchemy.exc.InvalidRequestError: Query.order_by() being called on a Query which already has LIMIT or OFFSET applied.  Call order_by() before limit() or offset() are applied.

To Reproduce
Install google-adk and run the following code with different config values.
Tested on PostgreSQL 15.10 (AWS Aurora).

def main():
    session_service = DatabaseSessionService(db_url=os.environ["ADK_DATABASE_URI"])
    session = session_service.get_session(
        app_name=app_name,
        user_id=user_id,
        session_id=session_id,
        # provide different values here
        config=GetSessionConfig(num_recent_events=10, after_timestamp=10.0),
    )
    print("Successfully got session")

Expected behavior
The session should be returned properly without raising errors.

Desktop (please complete the following information):

  • OS: MacOS(15.3.1)
  • Python version(python -V): 3.12.8
  • ADK version(pip show google-adk): 0.4.0

Metadata

Metadata

Assignees

Labels

services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions