adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column events.long_running_tool_ids_json does not exist

Open crisng95 opened this issue 1 year ago • 5 comments

Describe the bug I just upgraded ADK to 1.2.1 and got issue connect postgresql

db_url = "postgresql://postgres:PASSWORD@IP:5432/chat-session" session_service = DatabaseSessionService(db_url=db_url)

See image

Image

The error did not occur before (version 0.1.0). I try 0.5.0, 1.0.0, 1.2.1, all of them got the same issue like above.

To Reproduce Steps to reproduce the behavior:

  1. Install ADK above from 1.0.0 and DatabaseSessionService
  2. Run ADK web
  3. See error
line 943, in do_execute
    cursor.execute(statement, parameters)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedColumn) column events.long_running_tool_ids_json does not exist
LINE 1: ...events_content, events.actions AS events_actions, events.lon...
                                                             ^

[SQL: SELECT events.id AS events_id, events.app_name AS events_app_name, events.user_id AS events_user_id, events.session_id AS events_session_id, events.invocation_id AS events_invocation_id, events.author AS events_author, events.branch AS events_branch, events.timestamp AS events_timestamp, events.content AS events_content, events.actions AS events_actions, events.long_running_tool_ids_json AS events_long_running_tool_ids_json, events.grounding_metadata AS events_grounding_metadata, events.partial AS events_partial, events.turn_complete AS events_turn_complete, events.error_code AS events_error_code, events.error_message AS events_error_message, events.interrupted AS events_interrupted 
FROM events 
WHERE events.session_id = %(session_id_1)s ORDER BY events.timestamp DESC]
[parameters: {'session_id_1': 'chat_700572039796507_Ze3hP13GE8TeJbWvqEw6BwF91bp2'}]

crisng95 avatar Jun 05 '25 16:06 crisng95

Someone raised the issue about needing migrations https://github.com/google/adk-python/issues/456

I had written for myself a sql script to add the new columns, feel free to log in to your postgres database and run this :

DO $$
    BEGIN
        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'long_running_tool_ids_json'
        ) THEN
            ALTER TABLE events
                ADD COLUMN long_running_tool_ids_json JSONB;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'grounding_metadata'
        ) THEN
            ALTER TABLE events
                ADD COLUMN grounding_metadata JSONB;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'partial'
        ) THEN
            ALTER TABLE events
                ADD COLUMN partial BOOLEAN;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'turn_complete'
        ) THEN
            ALTER TABLE events
                ADD COLUMN turn_complete BOOLEAN;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'error_code'
        ) THEN
            ALTER TABLE events
                ADD COLUMN error_code TEXT;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'error_message'
        ) THEN
            ALTER TABLE events
                ADD COLUMN error_message TEXT;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'interrupted'
        ) THEN
            ALTER TABLE events
                ADD COLUMN interrupted BOOLEAN;
        END IF;
    END $$;

avidelatm avatar Jun 06 '25 09:06 avidelatm

Thanks @avidelatm for the script, @tuannguyenhoangit-droid could you try out this script?

DeanChensj avatar Jun 11 '25 20:06 DeanChensj

Thanks @avidelatm for the script, @tuannguyenhoangit-droid could you try out this script?

Does the bug be fixed on new release?

momo-tuannguyen12 avatar Jun 16 '25 03:06 momo-tuannguyen12

As far as I can tell no new migrations have been introduced since then, so if you are hoping to bump from your version to the latest 1.3.0 and for that to fix your issue, that won't be the case. You will either need to use the script I provided you, or delete your database/volumes and recreated it from scratch.
Unfortunately that is one of the risks of being early adopters of a framework/platform, specially in versions before a 1.0

avidelatm avatar Jun 17 '25 01:06 avidelatm

Someone raised the issue about needing migrations #456

I had written for myself a sql script to add the new columns, feel free to log in to your postgres database and run this :

DO $$
    BEGIN
        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'long_running_tool_ids_json'
        ) THEN
            ALTER TABLE events
                ADD COLUMN long_running_tool_ids_json JSONB;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'grounding_metadata'
        ) THEN
            ALTER TABLE events
                ADD COLUMN grounding_metadata JSONB;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'partial'
        ) THEN
            ALTER TABLE events
                ADD COLUMN partial BOOLEAN;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'turn_complete'
        ) THEN
            ALTER TABLE events
                ADD COLUMN turn_complete BOOLEAN;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'error_code'
        ) THEN
            ALTER TABLE events
                ADD COLUMN error_code TEXT;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'error_message'
        ) THEN
            ALTER TABLE events
                ADD COLUMN error_message TEXT;
        END IF;

        IF NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = current_schema()
              AND table_name = 'events'
              AND column_name = 'interrupted'
        ) THEN
            ALTER TABLE events
                ADD COLUMN interrupted BOOLEAN;
        END IF;
    END $$;

This work, thank BRO

crisng95 avatar Jun 23 '25 03:06 crisng95