Bucket.download_file_by_name fails when getting bucket with B2Api.get_bucket_by_id

Ouverte
#112 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
Une demi-journée
Accessibilité débutants
42/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
cloud

Piste de recherche

Start with download_file_by_name() in b2sdk/bucket.py, which assumes self.name is set, and compare it with get_bucket_by_name() to see how a Bucket built by B2Api.get_bucket_by_id() gets its name. Reproduce with the snippet in the issue, then check that a download by name works after fetching the bucket by id. The work is probably already superseded in the current release, so confirm against the latest code before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug good first issue

After getting a Bucket instance by calling B2Api.get_bucket_by_id(), I'm unable to download files with bucket.download_file_by_name(). A minimal example of the problem:

from b2sdk.v1 import InMemoryAccountInfo, B2Api, DownloadDestLocalFile

app_id = '<app_id>'
app_key = '<app_key>'
bucket_id = '<bucket_id>'
bucket_name = '<bucket_name>'

b2 = B2Api(InMemoryAccountInfo())
b2.authorize_account('production', app_id, app_key)

bucket = b2.get_bucket_by_id(bucket_id)
# bucket = b2.get_bucket_by_name(bucket_name)

dst = DownloadDestLocalFile('local_file_name')
bucket.download_file_by_name('<b2_file_path>', dst)

If the commented line that calls get_bucket_by_name() is used instead, the snippet works as expected.

Tried both v1.0.2 on PyPI and installing directly from master (more specifically 1707190972a5d6807c7d928dd5d295dce6920915).

The problem seems to be that the Bucket class assumes that its name attribute is always set in download_file_by_name() which is not a correct assumption when the bucket is instantiated with B2Api.get_bucket_by_id().

Is this a bug or have I missed something in the documentation?

Langage dominant
Python
Étoiles
214
Forks
68
Merge moyen
51 min
PR mergées (30 j)
6

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Backblaze/b2-sdk-python

Toutes les issues de Backblaze/b2-sdk-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.