Skip to content

Commit b008677

Browse files
authored
fix GetValuesAsync validation bug (Azure#24421)
1 parent 3118230 commit b008677

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- `AnalyzeActionsOperation.GetValuesAsync()` and `AnalyzeHealthcareEntitiesOperation.GetValuesAsync()` are now validating that the operation has completed successfully before attempting to return any values. An `InvalidOperationException` is thrown if this is not true.
1011

1112
### Other Changes
1213

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,12 @@ public override async ValueTask<Response<AsyncPageable<AnalyzeActionsResult>>> W
228228
/// <remarks>
229229
/// Operation must complete successfully (HasValue is true) for it to provide values.
230230
/// </remarks>
231-
public override AsyncPageable<AnalyzeActionsResult> GetValuesAsync(CancellationToken cancellationToken = default) => CreateOperationValueAsync(cancellationToken);
231+
public override AsyncPageable<AnalyzeActionsResult> GetValuesAsync(CancellationToken cancellationToken = default)
232+
{
233+
// Validates that the operation has completed successfully.
234+
_ = _operationInternal.Value;
235+
return CreateOperationValueAsync(cancellationToken);
236+
}
232237

233238
/// <summary>
234239
/// Gets the final result of the long-running operation synchronously.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ public virtual async Task CancelAsync(CancellationToken cancellationToken = defa
260260
/// <remarks>
261261
/// Operation must complete successfully (HasValue is true) for it to provide values.
262262
/// </remarks>
263-
public override AsyncPageable<AnalyzeHealthcareEntitiesResultCollection> GetValuesAsync(CancellationToken cancellationToken = default) => CreateOperationValueAsync(cancellationToken);
263+
public override AsyncPageable<AnalyzeHealthcareEntitiesResultCollection> GetValuesAsync(CancellationToken cancellationToken = default)
264+
{
265+
// Validates that the operation has completed successfully.
266+
_ = _operationInternal.Value;
267+
return CreateOperationValueAsync(cancellationToken);
268+
}
264269

265270
/// <summary>
266271
/// Gets the final result of the long-running operation in synchronously.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public async Task AnalyzeOperationWithPagination()
318318
Assert.IsFalse(operation.HasValue);
319319

320320
Assert.ThrowsAsync<InvalidOperationException>(async () => await Task.Run(() => operation.Value));
321-
Assert.Throws<InvalidOperationException>(() => operation.GetValues());
321+
Assert.ThrowsAsync<InvalidOperationException>(async () => await Task.Run(() => operation.GetValuesAsync()));
322322

323323
await operation.WaitForCompletionAsync();
324324

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public async Task AnalyzeHealthcareEntitiesPagination()
400400
Assert.IsFalse(operation.HasValue);
401401

402402
Assert.ThrowsAsync<InvalidOperationException>(async () => await Task.Run(() => operation.Value));
403-
Assert.Throws<InvalidOperationException>(() => operation.GetValues());
403+
Assert.ThrowsAsync<InvalidOperationException>(async () => await Task.Run(() => operation.GetValuesAsync()));
404404

405405
await operation.WaitForCompletionAsync();
406406

0 commit comments

Comments
 (0)