From 80f5683cd66182dbae87f956d70a3dc59b9960d2 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 14 Aug 2024 13:59:06 +0200 Subject: [PATCH] Raise on database error in recorder.migration._add_constraint (#123646) * Raise on database error in recorder.migration._add_constraint * Fix test --- homeassistant/components/recorder/migration.py | 1 + tests/components/recorder/test_migrate.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 55856dcf449..e96cef14cf4 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -727,6 +727,7 @@ def _add_constraint( connection.execute(add_constraint) except (InternalError, OperationalError): _LOGGER.exception("Could not update foreign options in %s table", table) + raise def _delete_foreign_key_violations( diff --git a/tests/components/recorder/test_migrate.py b/tests/components/recorder/test_migrate.py index 988eade29b6..2a33f08050c 100644 --- a/tests/components/recorder/test_migrate.py +++ b/tests/components/recorder/test_migrate.py @@ -962,9 +962,10 @@ def test_restore_foreign_key_constraints_with_error( engine = Mock() session_maker = Mock(return_value=session) - migration._restore_foreign_key_constraints( - session_maker, engine, constraints_to_restore - ) + with pytest.raises(InternalError): + migration._restore_foreign_key_constraints( + session_maker, engine, constraints_to_restore + ) assert "Could not update foreign options in events table" in caplog.text