diff --git a/ravendb/exceptions/cluster.py b/ravendb/exceptions/cluster.py index ffeed764..c866639f 100644 --- a/ravendb/exceptions/cluster.py +++ b/ravendb/exceptions/cluster.py @@ -1,9 +1,13 @@ from ravendb.exceptions.raven_exceptions import RavenException -class NoLoaderException(RavenException): +class NoLeaderException(RavenException): pass +# The name this class shipped under. +NoLoaderException = NoLeaderException + + class NodeIsPassiveException(RavenException): pass diff --git a/ravendb/exceptions/exception_dispatcher.py b/ravendb/exceptions/exception_dispatcher.py index 5b5dbf74..6fbf1a39 100644 --- a/ravendb/exceptions/exception_dispatcher.py +++ b/ravendb/exceptions/exception_dispatcher.py @@ -4,7 +4,7 @@ import os from datetime import timedelta -from ravendb.exceptions.cluster import NodeIsPassiveException, NoLoaderException +from ravendb.exceptions.cluster import NodeIsPassiveException, NoLeaderException from ravendb.exceptions.commercial import LicenseLimitException from ravendb.exceptions.documents import DocumentConflictException, DocumentDoesNotExistException from ravendb.exceptions.documents.bulkinsert import BulkInsertAbortedException, BulkInsertProtocolViolationException @@ -62,7 +62,7 @@ "ReplicationHubNotFoundException": ReplicationHubNotFoundException, # cluster "NodeIsPassiveException": NodeIsPassiveException, - "NoLoaderException": NoLoaderException, + "NoLeaderException": NoLeaderException, # commercial "LicenseLimitException": LicenseLimitException, } diff --git a/ravendb/tests/issue_tests/test_exception_dispatcher.py b/ravendb/tests/issue_tests/test_exception_dispatcher.py new file mode 100644 index 00000000..626dbac3 --- /dev/null +++ b/ravendb/tests/issue_tests/test_exception_dispatcher.py @@ -0,0 +1,34 @@ +import http +from unittest import TestCase + +from ravendb.exceptions.cluster import NoLeaderException, NoLoaderException +from ravendb.exceptions.exception_dispatcher import ExceptionDispatcher +from ravendb.exceptions.raven_exceptions import RavenException + + +def _dispatch(type_as_string: str) -> RavenException: + schema = ExceptionDispatcher.ExceptionSchema( + url="http://localhost:8080", + object_type=type_as_string, + message="no leader", + error="no leader", + ) + schema.type = type_as_string + return ExceptionDispatcher.get(schema, http.HTTPStatus.INTERNAL_SERVER_ERROR) + + +class TestExceptionDispatcher(TestCase): + def test_no_leader_from_the_server_is_typed(self): + # The map was keyed on "NoLoaderException", which the server never sends, so a real + # no-leader failure arrived as a plain RavenException. + exception = _dispatch("Raven.Client.Exceptions.Cluster.NoLeaderException") + + self.assertIsInstance(exception, NoLeaderException) + + def test_the_old_misspelled_name_is_still_importable(self): + self.assertIs(NoLeaderException, NoLoaderException) + + def test_an_unknown_type_stays_a_raven_exception(self): + exception = _dispatch("Raven.Client.Exceptions.Cluster.SomethingElseException") + + self.assertIs(RavenException, type(exception))