diff --git a/b2sdk/_internal/session.py b/b2sdk/_internal/session.py index 589c0cff..fa2a8959 100644 --- a/b2sdk/_internal/session.py +++ b/b2sdk/_internal/session.py @@ -525,7 +525,7 @@ def _add_app_key_info_to_unauthorized(self, unauthorized): new_message = unauthorized.message or 'unauthorized' new_message += ' for application key ' + ', '.join(key_messages) - return Unauthorized(new_message, unauthorized.code) + return type(unauthorized)(new_message, unauthorized.code) def _get_allowed_buckets_message(self, allowed) -> str | None: buckets = allowed['buckets'] diff --git a/changelog.d/+unauthorized-subclass.fixed.md b/changelog.d/+unauthorized-subclass.fixed.md new file mode 100644 index 00000000..a860d930 --- /dev/null +++ b/changelog.d/+unauthorized-subclass.fixed.md @@ -0,0 +1 @@ +`EmailNotVerified` and `NoPaymentHistory` are no longer turned into a plain `Unauthorized` by the session, so uploads fail right away instead of being retried. diff --git a/test/unit/test_session.py b/test/unit/test_session.py index a19cb522..31b79ed6 100644 --- a/test/unit/test_session.py +++ b/test/unit/test_session.py @@ -13,7 +13,7 @@ import pytest from apiver_deps import AuthInfoCache, B2Session, DummyCache, InMemoryAccountInfo -from apiver_deps_exception import Unauthorized +from apiver_deps_exception import EmailNotVerified, NoPaymentHistory, Unauthorized from .account_info.fixtures import * # noqa from .fixtures import * # noqa @@ -120,6 +120,19 @@ def test_app_key_info_all_info(self): ): self.b2_session.get_file_info_by_id(None) + @pytest.mark.apiver(from_ver=3) + @pytest.mark.parametrize('exc_class', [EmailNotVerified, NoPaymentHistory]) + def test_app_key_info_keeps_exception_type(self, exc_class): + self.b2_session.account_info.get_allowed.return_value = dict( + buckets=None, + capabilities=ALL_CAPABILITIES, + namePrefix=None, + ) + self.b2_session.raw_api.get_file_info_by_id.side_effect = exc_class('no_go', 'code') + + with pytest.raises(exc_class, match=r'no_go for application key with no restrictions'): + self.b2_session.get_file_info_by_id(None) + def test_session__with_in_memory_account_info(apiver_int): memory_info = InMemoryAccountInfo()