Skip to content

Commit 7811cbc

Browse files
authored
[TA] Change error in analyze (Azure#19197)
Fixes: Azure#18714
1 parent b8cb9a4 commit 7811cbc

File tree

5 files changed

+299
-14
lines changed

5 files changed

+299
-14
lines changed

sdk/textanalytics/Azure.AI.TextAnalytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- For `PiiEntity.Category` the type of the property is now `PiiEntityCategory` instead of `EntityCategory`.
2020
- Removed `RelatedEntities`.
2121
- `RecognizePiiEntitiesOptions.Domain` is now a nullable type.
22+
- In `StartAnalyzeBatchActions` when all actions return status `failed` the SDK will no longer throw an exception. The request will succeed and the errors will be located at the specific action level.
2223

2324
### Fixes
2425
- `RecognizePiiEntities` and `TextAnalyticsActions.RecognizePiiEntitiesOptions` were always passing `PiiEntityDomainType.PHI`. Now, it is only passed when requested by the user [19086](https://github.com/Azure/azure-sdk-for-net/issues/19086).

sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeBatchActionsOperation.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ public class AnalyzeBatchActionsOperation : PageableOperation<AnalyzeBatchAction
105105
/// </summary>
106106
public override bool HasCompleted => _hasCompleted;
107107

108-
/// <summary>
109-
/// If the operation has an exception, this property saves its information.
110-
/// </summary>
111-
private RequestFailedException _requestFailedException;
112-
113108
/// <summary>
114109
/// The last HTTP response received from the server. <c>null</c> until the first response is received.
115110
/// </summary>
@@ -263,20 +258,17 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke
263258
_totalActions = update.Value.Tasks.Total;
264259

265260
// TODO - Remove PartiallySucceeded once service deploys this to WestUS2
266-
if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded || update.Value.Status == TextAnalyticsOperationStatus.PartiallyCompleted)
261+
if (update.Value.Status == TextAnalyticsOperationStatus.Succeeded ||
262+
update.Value.Status == TextAnalyticsOperationStatus.PartiallySucceeded ||
263+
update.Value.Status == TextAnalyticsOperationStatus.PartiallyCompleted ||
264+
update.Value.Status == TextAnalyticsOperationStatus.Failed)
267265
{
268266
// we need to first assign a value and then mark the operation as completed to avoid race conditions
269267
var nextLink = update.Value.NextLink;
270268
var value = Transforms.ConvertToAnalyzeOperationResult(update.Value, _idToIndexMap);
271269
_firstPage = Page.FromValues(new List<AnalyzeBatchActionsResult>() { value }, nextLink, _response);
272270
_hasCompleted = true;
273271
}
274-
else if (update.Value.Status == TextAnalyticsOperationStatus.Failed)
275-
{
276-
_requestFailedException = await ClientCommon.CreateExceptionForFailedOperationAsync(async, _diagnostics, _response, update.Value.Errors).ConfigureAwait(false);
277-
_hasCompleted = true;
278-
throw _requestFailedException;
279-
}
280272
}
281273
catch (Exception e)
282274
{
@@ -350,8 +342,6 @@ private void ValidateOperationStatus()
350342
{
351343
if (!HasCompleted)
352344
throw new InvalidOperationException("The operation has not completed yet.");
353-
if (!HasValue)
354-
throw _requestFailedException;
355345
}
356346
}
357347
}

sdk/textanalytics/Azure.AI.TextAnalytics/tests/AnalyzeOperationTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,41 @@ public async Task AnalyzeOperationBatchWithErrorTest()
449449
Assert.AreEqual(TextAnalyticsErrorCode.InvalidRequest, linkedEntitiesActions[1].Error.ErrorCode.ToString());
450450
}
451451

452+
[Test]
453+
public async Task AnalyzeOperationBatchWithAllErrorsTest()
454+
{
455+
TextAnalyticsClient client = GetClient();
456+
457+
var documents = new List<string>
458+
{
459+
"Subject is taking 100mg of ibuprofen twice daily",
460+
"",
461+
};
462+
TextAnalyticsActions batchActions = new TextAnalyticsActions()
463+
{
464+
ExtractKeyPhrasesOptions = new List<ExtractKeyPhrasesOptions>()
465+
{
466+
new ExtractKeyPhrasesOptions()
467+
{
468+
ModelVersion = "InvalidVersion"
469+
}
470+
}
471+
};
472+
473+
AnalyzeBatchActionsOperation operation = await client.StartAnalyzeBatchActionsAsync(documents, batchActions, "en");
474+
await operation.WaitForCompletionAsync(PollingInterval);
475+
476+
//Take the first page
477+
AnalyzeBatchActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();
478+
479+
//Key phrases
480+
var keyPhrasesActions = resultCollection.ExtractKeyPhrasesActionsResults.ToList();
481+
482+
Assert.AreEqual(1, keyPhrasesActions.Count);
483+
Assert.IsTrue(keyPhrasesActions[0].HasError);
484+
Assert.AreEqual(TextAnalyticsErrorCode.InvalidRequest, keyPhrasesActions[0].Error.ErrorCode.ToString());
485+
}
486+
452487
[Test]
453488
public async Task AnalyzeOperationBatchWithPHIDomain()
454489
{

sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/AnalyzeOperationTests/AnalyzeOperationBatchWithAllErrorsTest.json

Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/textanalytics/Azure.AI.TextAnalytics/tests/SessionRecords/AnalyzeOperationTests/AnalyzeOperationBatchWithAllErrorsTestAsync.json

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)