Conversation
A row whose to_event() raises is logged and skipped, but the summary printed len(events) - the source row count - so a run that dropped rows reported the full count and then "Migration completed successfully". The pickle migration in the same package already counts successful inserts (migrate_from_sqlalchemy_pickle.py num_rows). Count the inserts here too and name the skipped ids, so the operator sees which events are still only in the source database.
Re-running the migration into the same destination fails with "UNIQUE constraint failed: sessions..." because the session rows are already there, so telling the operator to just re-run sends them into an error. The test now covers that advice end to end: a second run into a fresh destination recovers the skipped row, and re-running into the used one exits.
|
You are right, and I confirmed it end to end before changing the wording — a second Done in
I also ran your key-comparison workaround shape and it is the right instinct. The destination is not the only place to check, though: the sessions and app_states/user_states inserts run before events and have no per-row
One open question for the sessions owners, same as in #7300: I did not change whether the migration commits when rows are skipped. The pickle path commits too, so leaving it is consistent for now, but a run that reports success over a knowingly incomplete destination is a decision worth making explicitly. |
|
Thank you @feiiiiii5 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 31e5358. Closing this PR as the changes are now in the main branch. |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Testing Plan
Problem:
migrate_from_sqlalchemy_sqliteskips any event row whoseto_event()raises, warns per row, and then logsMigrated {len(events)} events.— the source row count. The transaction commits and the run ends withMigration completed successfully., so a run that dropped events claims the full count, and the skipped rows are only visible one warning at a time.migrate_from_sqlalchemy_picklein the same package already reports the number of successful inserts (num_rows).Solution:
Count the successful inserts and report that, then name the skipped ids in one warning so the operator knows the destination is incomplete while the source database still holds those events.
Unit Tests:
tests/unittests/sessions/migration/test_migration.py::test_sqlite_migration_reports_only_migrated_eventsbuilds a v0 database with two events, makes oneto_event()raise, runsmigrate(), and asserts the destination holdsevent1only, the log saysMigrated 1 events., does not sayMigrated 2 events., and namesevent2.main(044a1ec) that test fails: the log saysMigrated 2 events.with one row in the destination..venv/bin/python -m pytest tests/unittests/sessions/migration/ -q→ 61 passed.pre-commit run --files <changed files>→ fix end of files, trim trailing whitespace, ruff, isort, pyink, addlicense, codespell, ADK compliance checks and the doc-link check all pass..venv/bin/python -m mypy src/google/adk/sessions/migration/migrate_from_sqlalchemy_sqlite.py→ no issues.Manual End-to-End (E2E) Tests:
Not run — this is an offline migration script, and the regression test drives the real
migrate()against a real v0 SQLite database plus a real destination database, so the only mocked part is the oneto_event()call that raises.Checklist
Additional context
Scope is deliberately one file plus one test: the count, and the warning that names what was dropped. I did not change whether the migration commits when rows are skipped — the pickle path commits too, so that stays a separate decision for maintainers. Happy to drop the second warning if you would rather have only the corrected count.