Skip to content

feat: add client-level evaluation context setter#586

Draft
buildingisfun23 wants to merge 1 commit intoopen-feature:mainfrom
buildingisfun23:feat/500-client-evaluation-context
Draft

feat: add client-level evaluation context setter#586
buildingisfun23 wants to merge 1 commit intoopen-feature:mainfrom
buildingisfun23:feat/500-client-evaluation-context

Conversation

@buildingisfun23
Copy link
Copy Markdown

Summary

  • Adds set_evaluation_context() and get_evaluation_context() methods to OpenFeatureClient
  • Context merging was already implemented correctly (API -> transaction -> client -> invocation), the missing piece was just the setter
  • Adds 6 tests covering setter behavior, context replacement, and merge chain for both sync and async evaluations

Fixes #500

…atureClient

Allow setting evaluation context at the client level, following the
OpenFeature spec for context merging: API-level context is merged with
client-level context, then with invocation-level context, where later
levels take precedence over earlier ones.

Closes open-feature#500
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces client-level evaluation context management by adding set_evaluation_context and get_evaluation_context methods to the OpenFeatureClient class. It also includes comprehensive tests to verify context merging behavior across API, client, and invocation levels for both synchronous and asynchronous calls. The feedback suggests updating the context setter to handle potential None values by defaulting to an empty EvaluationContext, ensuring type consistency.

Comment on lines +100 to +101
def set_evaluation_context(self, context: EvaluationContext) -> None:
self.context = context
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To maintain consistency with the class constructor and ensure that self.context always holds a valid EvaluationContext instance (as expected by the type hint in get_evaluation_context), the setter should handle None by defaulting to an empty context. This prevents potential type errors if None is passed at runtime.

Suggested change
def set_evaluation_context(self, context: EvaluationContext) -> None:
self.context = context
def set_evaluation_context(self, context: EvaluationContext) -> None:
self.context = context or EvaluationContext()

@gruebel
Copy link
Copy Markdown
Member

gruebel commented Apr 11, 2026

please check this comment #565 (comment) for a previous PR targeting the same issue

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.

[FEATURE] client evaluation context support

2 participants