Skip to content

fix: return default value on async provider error resolution - #691

Open
xgbtxy wants to merge 1 commit into
open-feature:mainfrom
xgbtxy:fix/async-error-default-value
Open

xgbtxy wants to merge 1 commit into
open-feature:mainfrom
xgbtxy:fix/async-error-default-value

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Dec 1, 2026

Copy link
Copy Markdown

Summary

Per the OpenFeature Specification (Section 1.4.10):

Flag evaluation calls must always return the default value in the event of abnormal execution.

In OpenFeatureClient.evaluate_flag_details (sync, openfeature/client.py:806), when flag_evaluation.get_exception() is truthy (the provider returned FlagResolutionDetails with an error_code), the client explicitly resets flag_evaluation.value = default_value after running error_hooks and before returning (and passing flag_evaluation to finally_after hooks).

However, in OpenFeatureClient.evaluate_flag_details_async (openfeature/client.py:626-630), flag_evaluation.value = default_value was missing, so if an async provider returned FlagResolutionDetails(value=<non-default>, reason=Reason.ERROR, error_code=...), get_*_details_async / get_*_value_async and finally_after hooks received the provider's value instead of default_value. Similarly, _create_provider_evaluation (openfeature/client.py:949) passed value=resolution.value rather than value=default_value in its TYPE_MISMATCH return (unlike _create_provider_evaluation_async).

Changes

  • openfeature/client.py:
    • Set flag_evaluation.value = default_value in evaluate_flag_details_async when flag_evaluation.get_exception() returns an error, matching sync evaluate_flag_details.
    • Pass value=default_value in _create_provider_evaluation on _typecheck_flag_value failure, matching _create_provider_evaluation_async.
  • tests/test_client.py: Add test_should_return_default_value_if_provider_returns_resolution_with_error_code where the provider returns value=True with error_code=ErrorCode.PROVIDER_FATAL and the caller passes default_value=False, verifying both sync and async paths return False and pass False to finally_after hooks.

Verification

  • Verified get_boolean_details_async("k", False) returned True (while sync returned False) before the fix.
  • pytest tests -q: 227 passed.

@xgbtxy
xgbtxy requested review from a team as code owners December 1, 2026 23:10
Copilot AI balanced review requested due to automatic review settings December 1, 2026 23:10
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Evaluation results now use the caller’s default value in specified provider-error and type-mismatch cases. Tests cover synchronous and asynchronous provider-error evaluations, including returned details, error metadata, and hook behavior.

Changes: Evaluation default handling

Layer / File(s) Summary
Evaluation fallback values and tests
openfeature/client.py, tests/test_client.py
Async provider-error results and synchronous type-mismatch results use the caller’s default. Tests check returned values, finalization-hook details, retained error metadata, and hook counts for synchronous and asynchronous provider-error evaluations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: federicobond, gruebel

Merge Risk: Minimal · up to 1621e

This change makes async flag evaluation return the caller's default value when a provider reports an error, matching the sync behavior. It adds tests for this, and no merge-blocking risk is apparent.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the async evaluation path now returns the caller's default value when the provider resolution carries an error. It is specific and matches the summary and objectives, …
Description check Passed The description states the spec requirement, the async and sync discrepancy in evaluate_flag_details_async and _create_provider_evaluation, the specific code changes, the added test, and verification …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the async evaluation path now returns the caller's default value when the provider resolution carries an error. It is specific and matches the summary and objectives, which also cover the related type-mismatch fix in the sync path. The title follows the conventional 'fix:' form and is a single sentence.

Full details: Description check

Explanation

The description states the spec requirement, the async and sync discrepancy in evaluate_flag_details_async and _create_provider_evaluation, the specific code changes, the added test, and verification steps. It is directly related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3a89c5c8-1ed0-493d-a3a0-c2ebef030900
Commits

Reviewing files that changed from the base of the PR and between efd29b1 and 1621edc.

Files selected for processing: 2

  • openfeature/client.py
  • tests/test_client.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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_after hooks.
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 EmiRZx left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants