Skip to content

Commit 7f21254

Browse files
[documentintelligence] Fix copy operation polling (Azure#39957)
* fix polling for copy operation * update changelog * update changelog * async operation * update changelog date * pylint --------- Co-authored-by: catalinaperalta <[email protected]>
1 parent 8cac98e commit 7f21254

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

sdk/documentintelligence/azure-ai-documentintelligence/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
### Other Changes
1212

13+
## 1.0.1 (2025-03-11)
14+
15+
- Fix polling for `begin_copy_model_to()` to stop on success response from the "Operation-Location" endpoint and correctly parse the result.
16+
1317
## 1.0.0 (2024-12-17)
1418

1519
### Features Added

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/_operations/_patch.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=line-too-long,useless-suppression
12
# ------------------------------------
23
# Copyright (c) Microsoft Corporation.
34
# Licensed under the MIT License.
@@ -13,7 +14,7 @@
1314

1415
from azure.core.pipeline import PipelineResponse
1516
from azure.core.polling import LROPoller, NoPolling, PollingMethod
16-
from azure.core.polling.base_polling import LROBasePolling
17+
from azure.core.polling.base_polling import LROBasePolling, OperationResourcePolling
1718
from azure.core.rest import HttpRequest, HttpResponse
1819
from azure.core.tracing.decorator import distributed_trace
1920
from azure.core.utils import case_insensitive_dict
@@ -40,6 +41,17 @@ def _parse_operation_id(operation_location_header):
4041
return re.match(regex, operation_location_header).group(1)
4142

4243

44+
class DocumentModelAdministrationPolling(OperationResourcePolling):
45+
"""Polling method overrides for administration endpoints."""
46+
47+
def get_final_get_url(self, pipeline_response: Any) -> None:
48+
"""If a final GET is needed, returns the URL.
49+
50+
:param any pipeline_response: The pipeline response to get the final url.
51+
:rtype: None
52+
"""
53+
return None
54+
4355
class AnalyzeDocumentLROPoller(LROPoller[PollingReturnType_co]):
4456
@property
4557
def details(self) -> Mapping[str, Any]:
@@ -283,7 +295,7 @@ def get_long_running_output(pipeline_response):
283295
"str", response.headers.get("Operation-Location")
284296
)
285297

286-
deserialized = _deserialize(_models.DocumentModelDetails, response.json())
298+
deserialized = _deserialize(_models.DocumentModelDetails, response.json()["result"])
287299
if cls:
288300
return cls(pipeline_response, deserialized, response_headers) # type: ignore
289301
return deserialized
@@ -294,7 +306,7 @@ def get_long_running_output(pipeline_response):
294306

295307
if polling is True:
296308
polling_method: PollingMethod = cast(
297-
PollingMethod, LROBasePolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs)
309+
PollingMethod, LROBasePolling(lro_delay, path_format_arguments=path_format_arguments, lro_algorithms=[DocumentModelAdministrationPolling()], **kwargs)
298310
)
299311
elif polling is False:
300312
polling_method = cast(PollingMethod, NoPolling())

sdk/documentintelligence/azure-ai-documentintelligence/azure/ai/documentintelligence/aio/_operations/_patch.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from ... import models as _models
2525
from ..._model_base import _deserialize
26-
from ..._operations._patch import PollingReturnType_co, _parse_operation_id
26+
from ..._operations._patch import PollingReturnType_co, _parse_operation_id, DocumentModelAdministrationPolling
2727

2828
if sys.version_info >= (3, 9):
2929
from collections.abc import MutableMapping
@@ -265,7 +265,7 @@ def get_long_running_output(pipeline_response):
265265
"str", response.headers.get("Operation-Location")
266266
)
267267

268-
deserialized = _deserialize(_models.DocumentModelDetails, response.json())
268+
deserialized = _deserialize(_models.DocumentModelDetails, response.json()["result"])
269269
if cls:
270270
return cls(pipeline_response, deserialized, response_headers) # type: ignore
271271
return deserialized
@@ -277,7 +277,12 @@ def get_long_running_output(pipeline_response):
277277
if polling is True:
278278
polling_method: AsyncPollingMethod = cast(
279279
AsyncPollingMethod,
280-
AsyncLROBasePolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs),
280+
AsyncLROBasePolling(
281+
lro_delay,
282+
path_format_arguments=path_format_arguments,
283+
lro_algorithms=[DocumentModelAdministrationPolling()],
284+
**kwargs
285+
),
281286
)
282287
elif polling is False:
283288
polling_method = cast(AsyncPollingMethod, AsyncNoPolling())

0 commit comments

Comments
 (0)