Repository navigation
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the default-value error-handling changes.
No open issues 🎉
What changed in this PR
This PR aligns flag evaluation error handling with the OpenFeature requirement to return the caller’s default value on abnormal execution.
Changes:
- Reset async evaluation results to the default value when providers return an error code.
- Use the default value for synchronous type-mismatch results.
- Add regression coverage for sync and async error results, including values passed to
finally_afterhooks.
| File | Description |
|---|---|
tests/test_client.py |
Verify default values and hook results when providers return an error code. |
openfeature/client.py |
Correct default-value handling for async provider errors and sync type mismatches. |
Review effort: Balanced
EmiRZx
left a comment
There was a problem hiding this comment.
tested with a provider that returns a value along with an error code. async details, get_*_value_async and finally_after now get the default like the sync path, and the new test fails on main. the _create_provider_evaluation change doesn't show through the client though, since evaluate_flag_details already resets the value on any error code, so it aligns the two helpers rather than fixing a visible bug.
Summary
Per the OpenFeature Specification (Section 1.4.10):
In
OpenFeatureClient.evaluate_flag_details(sync,openfeature/client.py:806), whenflag_evaluation.get_exception()is truthy (the provider returnedFlagResolutionDetailswith anerror_code), the client explicitly resetsflag_evaluation.value = default_valueafter runningerror_hooksand before returning (and passingflag_evaluationtofinally_afterhooks).However, in
OpenFeatureClient.evaluate_flag_details_async(openfeature/client.py:626-630),flag_evaluation.value = default_valuewas missing, so if an async provider returnedFlagResolutionDetails(value=<non-default>, reason=Reason.ERROR, error_code=...),get_*_details_async/get_*_value_asyncandfinally_afterhooks received the provider's value instead ofdefault_value. Similarly,_create_provider_evaluation(openfeature/client.py:949) passedvalue=resolution.valuerather thanvalue=default_valuein itsTYPE_MISMATCHreturn (unlike_create_provider_evaluation_async).Changes
openfeature/client.py:flag_evaluation.value = default_valueinevaluate_flag_details_asyncwhenflag_evaluation.get_exception()returns an error, matching syncevaluate_flag_details.value=default_valuein_create_provider_evaluationon_typecheck_flag_valuefailure, matching_create_provider_evaluation_async.tests/test_client.py: Addtest_should_return_default_value_if_provider_returns_resolution_with_error_codewhere the provider returnsvalue=Truewitherror_code=ErrorCode.PROVIDER_FATALand the caller passesdefault_value=False, verifying both sync and async paths returnFalseand passFalsetofinally_afterhooks.Verification
get_boolean_details_async("k", False)returnedTrue(while sync returnedFalse) before the fix.pytest tests -q: 227 passed.