2424logger = logging .getLogger (__name__ )
2525logging .getLogger ("httpx" ).setLevel (logging .ERROR )
2626
27-
2827class LocalFeatureFlagsProvider :
2928 FLAGS_DEFINITIONS_URL_PATH = "/flags/definitions"
3029
@@ -319,12 +318,40 @@ def _get_assigned_rollout(
319318
320319 return None
321320
321+ def lowercase_keys_and_values (self , val : Any ) -> Any :
322+ if isinstance (val , str ):
323+ return val .casefold ()
324+ elif isinstance (val , list ):
325+ return [self .lowercase_keys_and_values (item ) for item in val ]
326+ elif isinstance (val , dict ):
327+ return {
328+ (key .casefold () if isinstance (key , str ) else key ):
329+ self .lowercase_keys_and_values (value )
330+ for key , value in val .items ()
331+ }
332+ else :
333+ return val
334+
335+ def lowercase_only_leaf_nodes (self , val : Any ) -> Dict [str , Any ]:
336+ if isinstance (val , str ):
337+ return val
338+ elif isinstance (val , list ):
339+ return [self .lowercase_keys_and_values (item ) for item in val ]
340+ elif isinstance (val , dict ):
341+ return {
342+ key :
343+ self .lowercase_keys_and_values (value )
344+ for key , value in val .items ()
345+ }
346+ else :
347+ return val
348+
322349 def _get_runtime_parameters (self , context : Dict [str , Any ]) -> Optional [Dict [str , Any ]]:
323350 if not (custom_properties := context .get ("custom_properties" )):
324351 return None
325352 if not isinstance (custom_properties , dict ):
326353 return None
327- return custom_properties
354+ return self . lowercase_keys_and_values ( custom_properties )
328355
329356 def _is_runtime_rules_engine_satisfied (self , rollout : Rollout , context : Dict [str , Any ]) -> bool :
330357 if rollout .runtime_evaluation_rule :
@@ -333,7 +360,8 @@ def _is_runtime_rules_engine_satisfied(self, rollout: Rollout, context: Dict[str
333360 return False
334361
335362 try :
336- result = json_logic .jsonLogic (rollout .runtime_evaluation_rule , parameters_for_runtime_rule )
363+ rule = self .lowercase_only_leaf_nodes (rollout .runtime_evaluation_rule )
364+ result = json_logic .jsonLogic (rule , parameters_for_runtime_rule )
337365 return bool (result )
338366 except Exception :
339367 logger .exception ("Error evaluating runtime evaluation rule" )
0 commit comments