Choose a feature variant from ordered rollout rules that can contain a faulty predicate.
Interface
Export create_feature_flag_engine(). It returns evaluate(flag, context). A flag has default_variant and optional rules. Each rule has when, a callable taking context, and variant, a string. An applicable variant "beta" wins over any later match.
Implement the contract in the supplied source file using Python 3. Discuss framework integration in design.md.
Behavior
- [F1] Call each synchronous predicate with context in input order. Only True matches. A match returns its variant and stops evaluation.
- [F2] With no match, return default_variant exactly. Omitted rules are an empty sequence.
- [F3] Treat a predicate exception as a non-match. Evaluate the same rule normally on later calls.
- [F4] Do not mutate the supplied flag, rules or context. Evaluate each call independently.
Design and verification
- Place the component in Django services, views and repository boundaries and explain the adapter/core boundary.
- Separate policy loading, rule evaluation and consumption of a variant.
- Explain where to record a failed predicate separately from a deliberate False result.