-
Notifications
You must be signed in to change notification settings - Fork 30
feat: implement transaction context #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
56c5a2f
feat: implement transaction context
lukas-reining 2a21b9d
fix: lint issues
lukas-reining 67e4368
feat: add tests for context merging
lukas-reining 7286042
feat: fix pre-commit checks
lukas-reining 7bf1cdc
feat: use elipsis instead of pass
lukas-reining b9d427c
Update openfeature/transaction_context/no_op_transaction_context_prop…
lukas-reining bb0e8bc
feat: pr feedback
lukas-reining 353fa1f
Merge branch 'main' into feat/transaction-context
gruebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from openfeature.transaction_context.context_var_transaction_context_propagator import ( | ||
| ContextVarsTransactionContextPropagator, | ||
| ) | ||
| from openfeature.transaction_context.no_op_transaction_context_propagator import ( | ||
| NoOpTransactionContextPropagator, | ||
| ) | ||
| from openfeature.transaction_context.transaction_context_propagator import ( | ||
| TransactionContextPropagator, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "TransactionContextPropagator", | ||
| "NoOpTransactionContextPropagator", | ||
| "ContextVarsTransactionContextPropagator", | ||
| ] | ||
18 changes: 18 additions & 0 deletions
18
openfeature/transaction_context/context_var_transaction_context_propagator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from contextvars import ContextVar | ||
|
|
||
| from openfeature.evaluation_context import EvaluationContext | ||
| from openfeature.transaction_context.transaction_context_propagator import ( | ||
| TransactionContextPropagator, | ||
| ) | ||
|
|
||
|
|
||
| class ContextVarsTransactionContextPropagator(TransactionContextPropagator): | ||
| _transaction_context_var: ContextVar[EvaluationContext] = ContextVar( | ||
| "transaction_context", default=EvaluationContext() | ||
| ) | ||
|
|
||
| def get_transaction_context(self) -> EvaluationContext: | ||
| return self._transaction_context_var.get() | ||
|
|
||
| def set_transaction_context(self, transaction_context: EvaluationContext) -> None: | ||
| self._transaction_context_var.set(transaction_context) |
13 changes: 13 additions & 0 deletions
13
openfeature/transaction_context/no_op_transaction_context_propagator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from openfeature.evaluation_context import EvaluationContext | ||
| from openfeature.transaction_context.transaction_context_propagator import ( | ||
| TransactionContextPropagator, | ||
| ) | ||
|
|
||
|
|
||
| class NoOpTransactionContextPropagator(TransactionContextPropagator): | ||
| def get_transaction_context(self) -> EvaluationContext: | ||
| return EvaluationContext() | ||
|
|
||
| def set_transaction_context( | ||
| self, transaction_context: EvaluationContext | ||
| ) -> None: ... | ||
lukas-reining marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
14 changes: 14 additions & 0 deletions
14
openfeature/transaction_context/transaction_context_propagator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import typing | ||
| from typing import TypeVar | ||
|
|
||
| from openfeature.evaluation_context import EvaluationContext | ||
|
|
||
| T = TypeVar("T", bound="TransactionContextPropagator") | ||
lukas-reining marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class TransactionContextPropagator(typing.Protocol): | ||
| def get_transaction_context(self) -> EvaluationContext: ... | ||
|
|
||
| def set_transaction_context( | ||
| self, transaction_context: EvaluationContext | ||
| ) -> None: ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.