|
6 | 6 | Two ways to evaluate a flag: |
7 | 7 | - Per-user/request: use the CouchersContext methods (context.get_boolean_value, get_string_value, |
8 | 8 | etc.), which evaluate for the context's user and own the per-request evaluator cache. |
9 | | - - Global (no user/request): use the module-level get_boolean_value / get_string_value / ... below. |
10 | | - These evaluate anonymously and are for background jobs and other code with no CouchersContext. |
| 9 | + - Global (no user/request): use the module-level get_global_boolean_value / get_global_string_value |
| 10 | + / ... below. Only for flags whose value genuinely can't be per-user - a toggle that behaves the |
| 11 | + same for everyone. Anything that is or could be per-user must use the context so rollouts and |
| 12 | + experiments can bucket by user. |
11 | 13 |
|
12 | 14 | Both paths share the enabled / pass-all-gates gating helpers here. setup_experimentation() is called |
13 | 15 | once at process startup. |
@@ -197,24 +199,27 @@ def _boolean_value(flag_key: str, default: bool, get_evaluator: Callable[[], Gro |
197 | 199 | return _feature_value(flag_key, default, get_evaluator) |
198 | 200 |
|
199 | 201 |
|
200 | | -# Global (no user/request) flag evaluation. Mirrors the CouchersContext.get_*_value API but |
201 | | -# evaluates anonymously: experiments and percentage rollouts are skipped (no user to bucket), so |
202 | | -# flags fall through to their in-code defaults unless a rule forces a value globally. |
203 | | -def get_boolean_value(flag_key: str, default: bool) -> bool: |
| 202 | +# Global (no-user) flag evaluation. Use these ONLY for a flag whose value genuinely cannot depend on |
| 203 | +# a user - one that toggles behavior the same way for everyone (e.g. a system-wide kill-switch or |
| 204 | +# behavior toggle). Anything that is or could be per-user must go through the CouchersContext methods |
| 205 | +# instead, so percentage rollouts and experiments can bucket by user. Here there is no user to |
| 206 | +# bucket, so rollouts and experiments are skipped and flags fall through to their in-code defaults |
| 207 | +# unless a rule forces a value globally. |
| 208 | +def get_global_boolean_value(flag_key: str, default: bool) -> bool: |
204 | 209 | return _boolean_value(flag_key, default, _global_evaluator) |
205 | 210 |
|
206 | 211 |
|
207 | | -def get_string_value(flag_key: str, default: str) -> str: |
| 212 | +def get_global_string_value(flag_key: str, default: str) -> str: |
208 | 213 | return _feature_value(flag_key, default, _global_evaluator) |
209 | 214 |
|
210 | 215 |
|
211 | | -def get_integer_value(flag_key: str, default: int) -> int: |
| 216 | +def get_global_integer_value(flag_key: str, default: int) -> int: |
212 | 217 | return _feature_value(flag_key, default, _global_evaluator) |
213 | 218 |
|
214 | 219 |
|
215 | | -def get_float_value(flag_key: str, default: float) -> float: |
| 220 | +def get_global_float_value(flag_key: str, default: float) -> float: |
216 | 221 | return _feature_value(flag_key, default, _global_evaluator) |
217 | 222 |
|
218 | 223 |
|
219 | | -def get_object_value[T](flag_key: str, default: T) -> T: |
| 224 | +def get_global_object_value[T](flag_key: str, default: T) -> T: |
220 | 225 | return _feature_value(flag_key, default, _global_evaluator) |
0 commit comments