fix(database/migration_runner): add check_same_thread=False to get_current_revision() SQLite engine #10897

Merged
HAL9000 merged 2 commits from bugfix/m3-sqlite-check-same-thread into master 2026-05-05 17:48:41 +00:00

2 Commits

Author SHA1 Message Date
HAL9000 1037e8e3ab fix(database/migration_runner): add check_same_thread=False to get_current_revision() SQLite engine
CI / benchmark-publish (pull_request) Has been skipped
CI / push-validation (pull_request) Successful in 34s
CI / helm (pull_request) Successful in 46s
CI / build (pull_request) Successful in 53s
CI / lint (pull_request) Successful in 1m0s
CI / benchmark-regression (pull_request) Failing after 1m29s
CI / quality (pull_request) Successful in 1m34s
CI / typecheck (pull_request) Successful in 1m42s
CI / security (pull_request) Successful in 1m42s
CI / integration_tests (pull_request) Successful in 3m42s
CI / unit_tests (pull_request) Successful in 4m35s
CI / e2e_tests (pull_request) Successful in 4m35s
CI / docker (pull_request) Successful in 1m29s
CI / coverage (pull_request) Successful in 13m7s
CI / status-check (pull_request) Successful in 4s
- Fix extra blank line in step file causing lint failure (ruff E302)
- Consolidate duplicate step_when_capture_engine_args and step_when_verify_thread_safe_args
  into a shared _run_get_current_revision_and_capture_kwargs() helper
- Remove duplicate Scenario 3 (identical assertion to Scenario 1, different step impl)
- Unify context attribute name to engine_creation_kwargs across all steps
- Add explicit type annotations to all step function signatures
2026-05-05 17:31:40 +00:00
HAL9000 023c0944a7 fix(database/migration_runner): add check_same_thread=False to get_current_revision() SQLite engine
MigrationRunner.get_current_revision() was creating a SQLAlchemy engine
with create_engine(self.database_url) without passing
connect_args={"check_same_thread": False} for SQLite databases.  When
called from a background thread (e.g. async startup flows), SQLite raised
ProgrammingError: SQLite objects created in a thread can only be used in
that same thread.

The sibling method init_or_upgrade() already passes check_same_thread=False
for SQLite, making this an inconsistency in the same class.  Because
get_pending_migrations() and check_migrations_needed() both delegate to
get_current_revision(), the threading bug propagated to all three methods.

This fix adds connect_args={"check_same_thread": False} to the
create_engine() call in get_current_revision() when the database URL
starts with "sqlite", consistent with the existing pattern in
init_or_upgrade().

ISSUES CLOSED: #10507
2026-05-05 17:31:40 +00:00