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 55s
CI / security (pull_request) Failing after 1m33s
CI / benchmark-regression (pull_request) Failing after 33s
CI / helm (pull_request) Failing after 15m1s
CI / build (pull_request) Failing after 15m3s
CI / e2e_tests (pull_request) Failing after 15m3s
CI / integration_tests (pull_request) Failing after 15m6s
CI / unit_tests (pull_request) Failing after 15m8s
CI / quality (pull_request) Failing after 15m9s
CI / typecheck (pull_request) Failing after 15m9s
CI / lint (pull_request) Failing after 15m9s
CI / coverage (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
CI / status-check (pull_request) Has been cancelled

Pass connect_args={"check_same_thread": False} when creating a SQLite engine
in get_current_revision(), consistent with init_or_upgrade() which already
applies this setting for all SQLite engines. Without this fix, calling
get_current_revision() from a different thread than the one that created
the engine raises a ProgrammingError.

ISSUES CLOSED: #10952
This commit is contained in:
2026-05-05 03:32:08 +00:00
parent 6236d6fc4f
commit b9e37bbf9c
3 changed files with 24 additions and 1 deletions
+6
View File
@@ -1714,6 +1714,12 @@ Feature: Consolidated Misc
And the temporary connection should be closed afterward
Scenario: Get current revision uses check_same_thread=False for SQLite
Given a migration runner configured for "sqlite:///:memory:"
When I request the current revision from the database
Then the get_current_revision engine should use check_same_thread False for SQLite
Scenario: File-based SQLite database directory is created if missing
Given a migration runner configured for "sqlite:///tmp/test-db/mydb.db"
When I initialize or upgrade a file-based SQLite database
+11
View File
@@ -316,6 +316,17 @@ def step_then_temp_connection_closed(context) -> None:
assert context.current_rev_fake_engine.connections[0].exit_called is True
@then("the get_current_revision engine should use check_same_thread False for SQLite")
def step_then_get_current_revision_check_same_thread(context) -> None:
_url, kwargs = context.current_rev_create_call
assert "connect_args" in kwargs, (
"Expected connect_args to be passed to create_engine for SQLite"
)
assert kwargs["connect_args"].get("check_same_thread") is False, (
"Expected check_same_thread=False in connect_args for SQLite"
)
@when("I initialize or upgrade a file-based SQLite database")
def step_when_init_file_based_sqlite(context) -> None:
import shutil
@@ -154,7 +154,13 @@ class MigrationRunner:
Returns:
Current revision ID or None if no migrations have been applied
"""
engine = create_engine(self.database_url)
if self.database_url.startswith("sqlite"):
engine = create_engine(
self.database_url,
connect_args={"check_same_thread": False},
)
else:
engine = create_engine(self.database_url)
with engine.connect() as connection:
context = MigrationContext.configure(connection)
return context.get_current_revision()