Polly icon indicating copy to clipboard operation
Polly copied to clipboard

PolicyKey and PolicyWrapKey are missing from PolicyResult.Context

Open sbaird32 opened this issue 4 years ago • 0 comments
trafficstars

Summary: When calling ExecuteAndCapture or ExecuteAndCaptureAsync on the respective policies with a PolicyKey set, the PolicyKey is missing from PolicyResult.Context. It does not matter whether a Context is passed in to these methods. If one is, any custom keys set on that context are preserved in PolicyResult.Context. Also the Context has all expected properties set within any delegates such as onRetry, including PolicyKey and PolicyWrapKey. However, these latter properties are null after policy execution.

Expected behavior: PolicyResult.Context.PolicyKey and PolicyResult.Context.PolicyWrapKey are set from the policy that was executed.

Actual behaviour: PolicyResult.Context.PolicyKey and PolicyResult.Context.PolicyWrapKey are both null.

Steps / Code to reproduce the problem:

Policy policy = Policy.Handle<Exception>().Retry().WithPolicyKey("TestPolicyKey");
PolicyResult policyResult = policy.ExecuteAndCapture(() => throw new Exception("Bad"));
Console.WriteLine(policyResult.Context.PolicyKey == null);

OR

Policy policy = Policy.Handle<Exception>().Retry().WithPolicyKey("TestPolicyKey");
PolicyResult policyResult = policy.ExecuteAndCapture(c => throw new Exception("Bad"), new Context("TestOperationKey"));
Console.WriteLine(policyResult.Context.PolicyKey == null);
Console.WriteLine(policyResult.Context.OperationKey != null);

sbaird32 avatar Feb 24 '21 18:02 sbaird32