Skip to content

Commit

Permalink
Change minimum SQLite version to 3.40.1 (#135042)
Browse files Browse the repository at this point in the history
Co-authored-by: J. Nick Koston <[email protected]>
  • Loading branch information
gjohansson-ST and bdraco authored Jan 9, 2025
1 parent c5f80dd commit 64752af
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 125 deletions.
4 changes: 0 additions & 4 deletions homeassistant/components/recorder/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
"backup_failed_out_of_resources": {
"title": "Database backup failed due to lack of resources",
"description": "The database backup stated at {start_time} failed due to lack of resources. The backup cannot be trusted and must be restarted. This can happen if the database is too large or if the system is under heavy load. Consider upgrading the system hardware or reducing the size of the database by decreasing the number of history days to keep or creating a filter."
},
"sqlite_too_old": {
"title": "Update SQLite to {min_version} or later to continue using the recorder",
"description": "Support for version {server_version} of SQLite is ending; the minimum supported version is {min_version}. Please upgrade your database software."
}
},
"services": {
Expand Down
50 changes: 2 additions & 48 deletions homeassistant/components/recorder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ def _simple_version(version: str) -> AwesomeVersion:
MARIADB_WITH_FIXED_IN_QUERIES_108 = _simple_version("10.8.4")
MIN_VERSION_MYSQL = _simple_version("8.0.0")
MIN_VERSION_PGSQL = _simple_version("12.0")
MIN_VERSION_SQLITE = _simple_version("3.31.0")
UPCOMING_MIN_VERSION_SQLITE = _simple_version("3.40.1")
MIN_VERSION_SQLITE_MODERN_BIND_VARS = _simple_version("3.32.0")
MIN_VERSION_SQLITE = _simple_version("3.40.1")
MIN_VERSION_SQLITE_MODERN_BIND_VARS = _simple_version("3.40.1")


# This is the maximum time after the recorder ends the session
Expand Down Expand Up @@ -376,37 +375,6 @@ def _raise_if_version_unsupported(
raise UnsupportedDialect


@callback
def _async_delete_issue_deprecated_version(
hass: HomeAssistant, dialect_name: str
) -> None:
"""Delete the issue about upcoming unsupported database version."""
ir.async_delete_issue(hass, DOMAIN, f"{dialect_name}_too_old")


@callback
def _async_create_issue_deprecated_version(
hass: HomeAssistant,
server_version: AwesomeVersion,
dialect_name: str,
min_version: AwesomeVersion,
) -> None:
"""Warn about upcoming unsupported database version."""
ir.async_create_issue(
hass,
DOMAIN,
f"{dialect_name}_too_old",
is_fixable=False,
severity=ir.IssueSeverity.CRITICAL,
translation_key=f"{dialect_name}_too_old",
translation_placeholders={
"server_version": str(server_version),
"min_version": str(min_version),
},
breaks_in_ha_version="2025.2.0",
)


def _extract_version_from_server_response_or_raise(
server_response: str,
) -> AwesomeVersion:
Expand Down Expand Up @@ -523,20 +491,6 @@ def setup_connection_for_dialect(
version or version_string, "SQLite", MIN_VERSION_SQLITE
)

# No elif here since _raise_if_version_unsupported raises
if version < UPCOMING_MIN_VERSION_SQLITE:
instance.hass.add_job(
_async_create_issue_deprecated_version,
instance.hass,
version or version_string,
dialect_name,
UPCOMING_MIN_VERSION_SQLITE,
)
else:
instance.hass.add_job(
_async_delete_issue_deprecated_version, instance.hass, dialect_name
)

if version and version > MIN_VERSION_SQLITE_MODERN_BIND_VARS:
max_bind_vars = SQLITE_MODERN_MAX_BIND_VARS

Expand Down
70 changes: 6 additions & 64 deletions tests/components/recorder/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from homeassistant.components.recorder.util import (
MIN_VERSION_SQLITE,
RETRYABLE_MYSQL_ERRORS,
UPCOMING_MIN_VERSION_SQLITE,
database_job_retry_wrapper,
end_incomplete_runs,
is_second_sunday,
Expand Down Expand Up @@ -236,7 +235,7 @@ def _make_cursor_mock(*_):

@pytest.mark.parametrize(
"sqlite_version",
[str(UPCOMING_MIN_VERSION_SQLITE)],
[str(MIN_VERSION_SQLITE)],
)
def test_setup_connection_for_dialect_sqlite(sqlite_version: str) -> None:
"""Test setting up the connection for a sqlite dialect."""
Expand Down Expand Up @@ -289,7 +288,7 @@ def _make_cursor_mock(*_):

@pytest.mark.parametrize(
"sqlite_version",
[str(UPCOMING_MIN_VERSION_SQLITE)],
[str(MIN_VERSION_SQLITE)],
)
def test_setup_connection_for_dialect_sqlite_zero_commit_interval(
sqlite_version: str,
Expand Down Expand Up @@ -510,11 +509,11 @@ def _make_cursor_mock(*_):
[
(
"3.30.0",
"Version 3.30.0 of SQLite is not supported; minimum supported version is 3.31.0.",
"Version 3.30.0 of SQLite is not supported; minimum supported version is 3.40.1.",
),
(
"2.0.0",
"Version 2.0.0 of SQLite is not supported; minimum supported version is 3.31.0.",
"Version 2.0.0 of SQLite is not supported; minimum supported version is 3.40.1.",
),
],
)
Expand Down Expand Up @@ -552,8 +551,8 @@ def _make_cursor_mock(*_):
@pytest.mark.parametrize(
"sqlite_version",
[
("3.31.0"),
("3.33.0"),
("3.40.1"),
("3.41.0"),
],
)
def test_supported_sqlite(caplog: pytest.LogCaptureFixture, sqlite_version) -> None:
Expand Down Expand Up @@ -734,63 +733,6 @@ def _make_cursor_mock(*_):
assert database_engine.optimizer.slow_range_in_select is False


async def test_issue_for_old_sqlite(
hass: HomeAssistant,
issue_registry: ir.IssueRegistry,
) -> None:
"""Test we create and delete an issue for old sqlite versions."""
instance_mock = MagicMock()
instance_mock.hass = hass
execute_args = []
close_mock = MagicMock()
min_version = str(MIN_VERSION_SQLITE)

def execute_mock(statement):
nonlocal execute_args
execute_args.append(statement)

def fetchall_mock():
nonlocal execute_args
if execute_args[-1] == "SELECT sqlite_version()":
return [[min_version]]
return None

def _make_cursor_mock(*_):
return MagicMock(execute=execute_mock, close=close_mock, fetchall=fetchall_mock)

dbapi_connection = MagicMock(cursor=_make_cursor_mock)

database_engine = await hass.async_add_executor_job(
util.setup_connection_for_dialect,
instance_mock,
"sqlite",
dbapi_connection,
True,
)
await hass.async_block_till_done()

issue = issue_registry.async_get_issue(DOMAIN, "sqlite_too_old")
assert issue is not None
assert issue.translation_placeholders == {
"min_version": str(UPCOMING_MIN_VERSION_SQLITE),
"server_version": min_version,
}

min_version = str(UPCOMING_MIN_VERSION_SQLITE)
database_engine = await hass.async_add_executor_job(
util.setup_connection_for_dialect,
instance_mock,
"sqlite",
dbapi_connection,
True,
)
await hass.async_block_till_done()

issue = issue_registry.async_get_issue(DOMAIN, "sqlite_too_old")
assert issue is None
assert database_engine is not None


@pytest.mark.skip_on_db_engine(["mysql", "postgresql"])
@pytest.mark.usefixtures("skip_by_db_engine")
async def test_basic_sanity_check(
Expand Down
9 changes: 0 additions & 9 deletions tests/components/sensor/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ def disable_mariadb_issue() -> None:
yield


@pytest.fixture(autouse=True)
def disable_sqlite_issue() -> None:
"""Disable creating issue about outdated SQLite version."""
with patch(
"homeassistant.components.recorder.util._async_create_issue_deprecated_version"
):
yield


async def async_list_statistic_ids(
hass: HomeAssistant,
statistic_ids: set[str] | None = None,
Expand Down

0 comments on commit 64752af

Please sign in to comment.