Azure / Azure/azure-storage-python

BaseBlobService.get_blob_to_stream doesn't accept io.StringIO as a stream

オープン
#536 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
343
フォーク
243
PR マージ指標
30日以内にマージされた PR はありません

説明

### Which service(blob, file, queue) does this issue concern?

Blob

### Which version of the SDK was used? Please provide the output of `pip freeze`.

```
azure-storage-blob==1.4.0
azure-storage-common==1.4.0
azure-storage-file==1.4.0
azure-storage-nspkg==3.0.0
azure-storage-queue==1.4.0
```

### What problem was encountered?

```python
from azure.storage.blob.baseblobservice import BaseBlobService
import io

file_uri = "..."
blob_service = BaseBlobService(connection_string="...")

string_stream = io.StringIO()
string_result = blob_service.get_blob_to_stream("...", "....csv", stream=string_stream)
```

Fails with:
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
1 string_stream = io.StringIO()
----> 2 string_result = blob_service.get_blob_to_stream("...", ".....csv", stream=string_stream)
3 #print("content type: {}".format(type(string_stream)))

~/miniconda3/envs/py36/lib/python3.6/site-packages/azure/storage/blob/baseblobservice.py in get_blob_to_stream(self, container_name, blob_name, stream, snapshot, start_range, end_range, validate_content, progress_callback, max_connections, lease_id, if_modified_since, if_unmodified_since, if_match, if_none_match, timeout)
2052 # Clear blob content since output has been written to user stream
2053 if blob.content is not None:
-> 2054 stream.write(blob.content)
2055 blob.content = None
2056

TypeError: string argument expected, got 'bytes'
```

Even though accordin to the docs the [stream param](https://azure-storage.readthedocs.io/ref/azure.storage.blob.baseblobservice.html?highlight=get_blob_to_stream#azure.storage.blob.baseblobservice.BaseBlobService.get_blob_to_stream) is an `io.IOBase` and `issubclass(io.StringIO, io.IOBase)` is `True`.
Am I missing something?

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

azure/storage/blob/baseblobservice.py の BaseBlobService.get_blob_to_stream から始め、traceback に示されている stream.write(blob.content) のパスを確認します。io.StringIO とドキュメントに記載された stream パラメーターを使って失敗を再現し、その後、サポートされている stream の動作が回帰テストでカバーされていること、および StringIO のケースで報告された TypeError が発生しなくなったことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
cloud
issue の種類
バグ
難易度
2/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。