You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2026/09/19 13:48:54 UTC
(superset) branch master updated: test(versioning): mock the restore locking re-read in the #44253 LookupError tests (fixes red master) (#44445)
This is an automated email from the ASF dual-hosted git repository.
aminghadersohi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 43fee876722 test(versioning): mock the restore locking re-read in the #44253 LookupError tests (fixes red master) (#44445)
43fee876722 is described below
commit 43fee87672297d2217ad297b1e80042a4358074b
Author: Mike Bridge <mi...@preset.io>
AuthorDate: Sat Sep 19 07:48:46 2026 -0600
test(versioning): mock the restore locking re-read in the #44253 LookupError tests (fixes red master) (#44445)
---
.../commands/test_base_restore_version_command.py | 54 +++++++++++++++++-----
1 file changed, 43 insertions(+), 11 deletions(-)
diff --git a/tests/unit_tests/commands/test_base_restore_version_command.py b/tests/unit_tests/commands/test_base_restore_version_command.py
index f7310c00cd9..2012931263e 100644
--- a/tests/unit_tests/commands/test_base_restore_version_command.py
+++ b/tests/unit_tests/commands/test_base_restore_version_command.py
@@ -99,6 +99,27 @@ def test_validate_returns_entity_when_not_managed_externally(
assert cmd.validate() is entity
+@contextmanager
+def _restore_context(entity: MagicMock) -> Iterator[None]:
+ """Supply the validated entity through the locking read as well.
+
+ Keep the transaction/error wrapper real so these tests exercise exception
+ translation from the restore engine, not a database binding failure.
+ Lock ordering and predicates are covered in test_restore_version_concurrency.
+ """
+ query: MagicMock = MagicMock()
+ query.populate_existing.return_value = query
+ query.enable_eagerloads.return_value = query
+ query.filter_by.return_value = query
+ query.with_for_update.return_value = query
+ query.one_or_none.return_value = entity
+ with (
+ _validate_context(entity),
+ patch("superset.commands.version_restore.db.session.query", return_value=query),
+ ):
+ yield
+
+
@pytest.mark.parametrize("command_cls", _COMMAND_CLASSES)
def test_registry_lookup_error_maps_to_failed_exc(
command_cls: type[BaseRestoreVersionCommand],
@@ -110,10 +131,13 @@ def test_registry_lookup_error_maps_to_failed_exc(
SQLAlchemyError default that surfaced as a raw 500 instead of the
intended fail-closed 422 (sc-115326).
"""
- entity = MagicMock(is_managed_externally=False)
- lookup = LookupError("No restore relations registered for 'Widget'")
+ entity: MagicMock = MagicMock(id=123, is_managed_externally=False)
+ lookup: LookupError = LookupError("No restore relations registered for 'Widget'")
+ cmd: BaseRestoreVersionCommand = command_cls(uuid4(), uuid4())
+ restore: MagicMock
+ excinfo: pytest.ExceptionInfo[Exception]
with (
- _validate_context(entity),
+ _restore_context(entity),
patch(
"superset.commands.version_restore.resolve_version",
return_value=(0, 123),
@@ -121,12 +145,13 @@ def test_registry_lookup_error_maps_to_failed_exc(
patch(
"superset.commands.version_restore.restore_version",
side_effect=lookup,
- ),
+ ) as restore,
):
with pytest.raises(command_cls.failed_exc) as excinfo:
- command_cls(uuid4(), uuid4()).run()
+ cmd.run()
assert excinfo.value.__cause__ is lookup
+ restore.assert_called_once_with(cmd.model_cls, cmd._uuid, 123, entity=entity)
@pytest.mark.parametrize("command_cls", _COMMAND_CLASSES)
@@ -135,17 +160,24 @@ def test_other_exceptions_still_pass_through_untranslated(
) -> None:
"""The catches tuple stays narrow: an arbitrary non-SQLAlchemy error
propagates as itself — the endpoint maps such types explicitly."""
- entity = MagicMock(is_managed_externally=False)
+ entity: MagicMock = MagicMock(id=123, is_managed_externally=False)
+ error: RuntimeError = RuntimeError("boom")
+ cmd: BaseRestoreVersionCommand = command_cls(uuid4(), uuid4())
+ restore: MagicMock
+ excinfo: pytest.ExceptionInfo[RuntimeError]
with (
- _validate_context(entity),
+ _restore_context(entity),
patch(
"superset.commands.version_restore.resolve_version",
return_value=(0, 123),
),
patch(
"superset.commands.version_restore.restore_version",
- side_effect=RuntimeError("boom"),
- ),
+ side_effect=error,
+ ) as restore,
):
- with pytest.raises(RuntimeError):
- command_cls(uuid4(), uuid4()).run()
+ with pytest.raises(RuntimeError) as excinfo:
+ cmd.run()
+
+ assert excinfo.value is error
+ restore.assert_called_once_with(cmd.model_cls, cmd._uuid, 123, entity=entity)