Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b2sdk v2 delete_bucket() throws v3.BucketIdNotFound exception #437

Closed
mjurbanski-reef opened this issue Nov 15, 2023 · 0 comments · Fixed by #494
Closed

b2sdk v2 delete_bucket() throws v3.BucketIdNotFound exception #437

mjurbanski-reef opened this issue Nov 15, 2023 · 0 comments · Fixed by #494
Labels
bug Something isn't working

Comments

@mjurbanski-reef
Copy link
Collaborator

mjurbanski-reef commented Nov 15, 2023

This is especially problematic, as _v3 is still unreleased, it's hard to catch in a manner that won't break on next b2sdk update.
That case is supposed to be handled by current code, but somehow error translation still fails (tested against current master branch).

../b2-sdk-python/b2sdk/api.py:386: in delete_bucket
    self.session.delete_bucket(account_id, bucket.id_)
../b2-sdk-python/b2sdk/session.py:183: in delete_bucket
    return self._wrap_default_token(self.raw_api.delete_bucket, account_id, bucket_id)
../b2-sdk-python/b2sdk/session.py:456: in _wrap_default_token
    return self._wrap_token(raw_api_method, TokenType.API, *args, **kwargs)
../b2-sdk-python/b2sdk/session.py:462: in _wrap_token
    return self._reauthorization_loop(partial_callback)
../b2-sdk-python/b2sdk/session.py:477: in _reauthorization_loop
    return callback()
../b2-sdk-python/b2sdk/session.py:467: in _api_token_callback
    return raw_api_method(api_url, account_auth_token, *args, **kwargs)
../b2-sdk-python/b2sdk/raw_api.py:530: in delete_bucket
    bucketId=bucket_id
../b2-sdk-python/b2sdk/raw_api.py:458: in _post_json
    return self.b2_http.post_json_return_json(url, headers, params)
../b2-sdk-python/b2sdk/b2http.py:309: in post_json_return_json
    _timeout=timeout,
../b2-sdk-python/b2sdk/b2http.py:262: in post_content_return_json
    response = self._translate_and_retry(do_post, try_count, post_params)
../b2-sdk-python/b2sdk/b2http.py:507: in _translate_and_retry
    return cls._translate_errors(fcn, post_params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'b2sdk.v2.b2http.B2Http'>
fcn = <function B2Http.post_content_return_json.<locals>.do_post at 0x7f9cd89ca5f0>
post_params = {'accountId': 'censored', 'bucketId': '2a71a86d67b1d13b83b50e14'}

    @classmethod
    def _translate_errors(cls, fcn, post_params=None):
        """
        Call the given function, turning any exception raised into the right
        kind of B2Error.
    
        :param dict post_params: request parameters
        """
        response = None
        try:
            response = fcn()
            if response.status_code not in [200, 206]:
                # Decode the error object returned by the service
                error = json.loads(response.content.decode('utf-8')) if response.content else {}
                extra_error_keys = error.keys() - ('code', 'status', 'message')
                if extra_error_keys:
                    logger.debug(
                        'received error has extra (unsupported) keys: %s', extra_error_keys
                    )
                raise interpret_b2_error(
                    int(error.get('status', response.status_code)),
                    error.get('code'),
                    error.get('message'),
                    response.headers,
>                   post_params,
                )
E               b2sdk.exception.BucketIdNotFound: Bucket with id=2a71a86d67b1d13b83b50e14 not found

../b2-sdk-python/b2sdk/b2http.py:436: BucketIdNotFound

This doesn't quite seem "apiver" legal (more like accidental export to public api), but to catch these I'm using from b2sdk.v2.exception import v3BucketIdNotFound now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant