Azure / Azure/azure-sdk-for-python

poller.continuation_token() crashes if initial request use file stream as input

Offen
#38,713 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Azure.Core bug Client customer-reported needs-team-attention
Vorherrschende Sprache
Python
Sterne
5.6k
Forks
3.4k
Ø Merge
2 T. 2 Std.
Gemergte PRs (30 T.)
213

Beschreibung

  • Package Name: azure-ai-documentintelligence
  • Package Version: 1.0.0b4
  • Operating System: Windows
  • Python Version: 3.12.7

Describe the bug
poller.continuation_token() crashes if input file is passed as an octet-steam into initial begin_analyze_document call.

Exception is below:

Traceback (most recent call last):
  File "C:\temp\SDK_issue_report.py", line 25, in <module>
    poller_continuation_token = poller.continuation_token() # get continuation token FAILS
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\anatolip\AppData\Local\anaconda3\envs\py12\Lib\site-packages\azure\core\polling\_poller.py", line 224, in continuation_token
    return self._polling_method.get_continuation_token()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\anatolip\AppData\Local\anaconda3\envs\py12\Lib\site-packages\azure\core\polling\base_polling.py", line 651, in get_continuation_token
    return base64.b64encode(pickle.dumps(self._initial_response)).decode("ascii")
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot pickle 'BufferedReader' instances

To Reproduce
Code below illustrates that continuation_token() works if file is passed to begin_analyze_document as base64 string, but if file is passed as a octet-stream, get continuation_token() fails.

from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest
import base64, pickle, os

endpoint = os.environ["AZURE_DI_ENDPOINT"]
key = os.environ["AZURE_DI_KEY"]

path_to_sample_documents = r'c:\temp\SampleInvoice26andLineItems.pdf'

client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key))

with open(path_to_sample_documents, "rb") as f:
    poller = client.begin_analyze_document("prebuilt-layout", AnalyzeDocumentRequest(bytes_source=f.read()))
poller_continuation_token = poller.continuation_token() # get continuation token WORKS
decoded_token = pickle.loads(base64.b64decode(poller_continuation_token))
resultUrl = decoded_token.http_response.headers.get('Operation-Location')
print(f"Results URL from continuation_token: {resultUrl} \n")

with open(path_to_sample_documents, "rb") as f:
    poller = client.begin_analyze_document("prebuilt-layout", f, content_type="application/octet-stream")
print(f"ERROR during continuation_token!!!\n")
poller_continuation_token = poller.continuation_token() # get continuation token FAILS

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit azure/core/polling/_poller.py und base_polling.py und folge poller.continuation_token() zu get_continuation_token(). Vergleiche die begin_analyze_document-Aufrufe mit AnalyzeDocumentRequest(bytes_source=...) und den Dateistream mit content_type="application/octet-stream". Fertig ist es, wenn continuation_token() für die Stream-Eingabe nicht mehr abstürzt und die Operationsposition beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.