RuntimeWarning: coroutine 'DocumentIntelligenceClientOperationsMixin.begin_classify_document' was never awaited
- Package Name: azure-ai-documentintelligence
- Package Version: 1.0.0b2
- Operating System: Windows
- Python Version: 3.10.9
Describe the bug The reproducible code was working fine for me, nothing has changed, the run time warning has never happen before till today. The studio was working fine for me and environment variables have not changed too. I am developing from jupyter notebook using the python sdk.
To Reproduce Steps to reproduce the behavior:
import os
from azure.ai.documentintelligence.aio import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import ClassifyDocumentRequest
from dotenv import load_dotenv
load_dotenv()
doc_intel_endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT")
doc_intel_key = os.getenv("AZURE_FORM_RECOGNIZER_KEY")
document_intelligence_client = DocumentIntelligenceClient(
endpoint=doc_intel_endpoint,
credential=AzureKeyCredential(doc_intel_key)
)
def classify_document(classifier_id, blob_sas_url):
try:
class_result = document_intelligence_client.begin_classify_document(
classifier_id=classifier_id,
classify_request=ClassifyDocumentRequest(
url_source=blob_sas_url
)
).result()
except Exception as error:
print(f'ERROR: Classification failed: {error}')
return None
return class_result
CLASSIFIER_MODEL = my_custom_classifier
blob_sas_url = document_blob_sas_url
class_result = classify_document(CLASSIFIER_MODEL, blob_sas_url)
ERROR: Classification failed: 'coroutine' object has no attribute 'result'
RuntimeWarning: coroutine 'DocumentIntelligenceClientOperationsMixin.begin_classify_document' was never awaited
return None
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Expected behavior
.result() to return with the classification results.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ctstone @vkurpad.
Thank you for the feedback @galvangoh
Can you try making the following changes to your code please. The code sample is using the async version of the client but the results are not being awaited.
You can either use the sync code by changing the import to
from azure.ai.documentintelligence import DocumentIntelligenceClient
or if you want to use async, then make the following modifications to the repro code.
import os
import asyncio
from azure.ai.documentintelligence.aio import DocumentIntelligenceClient
from azure.ai.documentintelligence.models import ClassifyDocumentRequest
from dotenv import load_dotenv
load_dotenv()
doc_intel_endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT")
doc_intel_key = os.getenv("AZURE_FORM_RECOGNIZER_KEY")
document_intelligence_client = DocumentIntelligenceClient(
endpoint=doc_intel_endpoint,
credential=AzureKeyCredential(doc_intel_key)
)
async def classify_document(classifier_id, blob_sas_url):
try:
class_result = await document_intelligence_client.begin_classify_document(
classifier_id=classifier_id,
classify_request=ClassifyDocumentRequest(
url_source=blob_sas_url
)
).result()
except Exception as error:
print(f'ERROR: Classification failed: {error}')
return None
return class_result
async def main():
CLASSIFIER_MODEL = my_custom_classifier
blob_sas_url = document_blob_sas_url
class_result = classify_document(CLASSIFIER_MODEL, blob_sas_url)
asyncio.run(main())
Hi @galvangoh. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Hello @kashifkhan, changing the import works, thank you!