Skip to content

Commit e69e17a

Browse files
committed
Add get_feature_value helper and restore disabled-init log
Adds a generic typed get_feature_value(context, name, default) so callers can read strings, numbers, dicts, and experiment variations - not just boolean gates. Also restores the 'Experimentation is disabled' log line that got trimmed in the initial swap.
1 parent 6659ebd commit e69e17a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

app/backend/src/couchers/experimentation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def setup_experimentation() -> None:
3636
return
3737

3838
if not config["EXPERIMENTATION_ENABLED"]:
39+
logger.info("Experimentation is disabled, skipping initialization")
3940
_initialized = True
4041
return
4142

@@ -89,3 +90,17 @@ def check_gate(context: CouchersContext, gate_name: str) -> bool:
8990
if not config["EXPERIMENTATION_ENABLED"]:
9091
return False
9192
return _get_growthbook(context).is_on(gate_name)
93+
94+
95+
def get_feature_value[T](context: CouchersContext, feature_name: str, default: T) -> T:
96+
"""
97+
Get the value of a feature for the user in this context.
98+
99+
Use this for non-boolean features: strings, numbers, dicts, experiment variations,
100+
dynamic configs - anything other than a simple on/off gate. The default's type
101+
determines the return type and is returned verbatim when experimentation is disabled.
102+
"""
103+
_check_initialized()
104+
if not config["EXPERIMENTATION_ENABLED"]:
105+
return default
106+
return _get_growthbook(context).get_feature_value(feature_name, default) # type: ignore[no-any-return]

0 commit comments

Comments
 (0)