Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion b2sdk/_internal/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+unauthorized-subclass.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 14 additions & 1 deletion test/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down