@@ -847,16 +847,10 @@ def get_feature_flag(
847847 flag_was_locally_evaluated = response is not None
848848 if not flag_was_locally_evaluated and not only_evaluate_locally :
849849 try :
850- feature_flags = self .get_feature_variants (
851- distinct_id ,
852- groups = groups ,
853- person_properties = person_properties ,
854- group_properties = group_properties ,
855- disable_geoip = disable_geoip ,
850+ flag_details , request_id = self ._get_feature_flag_details_from_decide (
851+ key , distinct_id , groups , person_properties , group_properties , disable_geoip
856852 )
857- response = feature_flags .get (key )
858- if response is None :
859- response = False
853+ response = flag_details .get_value () if flag_details else False
860854 self .log .debug (f"Successfully computed flag remotely: #{ key } -> #{ response } " )
861855 except Exception as e :
862856 self .log .exception (f"[FEATURE FLAGS] Unable to get flag remotely: { e } " )
@@ -871,7 +865,7 @@ def get_feature_flag(
871865 groups ,
872866 disable_geoip ,
873867 request_id ,
874- flag_details
868+ flag_details ,
875869 )
876870
877871 return response
@@ -943,20 +937,15 @@ def get_feature_flag_payload(
943937 flag_was_locally_evaluated = payload is not None
944938 if not flag_was_locally_evaluated and not only_evaluate_locally :
945939 try :
946- responses_and_payloads = self .get_feature_flags_and_payloads (
947- distinct_id , groups , person_properties , group_properties , disable_geoip
940+ flag_details , request_id = self ._get_feature_flag_details_from_decide (
941+ key , distinct_id , groups , person_properties , group_properties , disable_geoip
948942 )
949- featureFlags = responses_and_payloads ["featureFlags" ]
950- if featureFlags is not None :
951- response = featureFlags .get (key , None )
952-
953- featureFlagPayloads = responses_and_payloads ["featureFlagPayloads" ]
954- if featureFlagPayloads is not None :
955- payload = featureFlagPayloads .get (str (key ), None )
943+ payload = flag_details .metadata .payload if flag_details else None
944+ response = flag_details .get_value () if flag_details else False
956945 except Exception as e :
957946 self .log .exception (f"[FEATURE FLAGS] Unable to get feature flags and payloads: { e } " )
958947
959- if ( send_feature_flag_events ) :
948+ if send_feature_flag_events :
960949 self ._capture_feature_flag_called (
961950 distinct_id ,
962951 key ,
@@ -966,11 +955,29 @@ def get_feature_flag_payload(
966955 groups ,
967956 disable_geoip ,
968957 request_id ,
969- flag_details
958+ flag_details ,
970959 )
971960
972961 return payload
973962
963+ def _get_feature_flag_details_from_decide (
964+ self ,
965+ key : str ,
966+ distinct_id : str ,
967+ groups : dict [str , str ],
968+ person_properties : dict [str , str ],
969+ group_properties : dict [str , str ],
970+ disable_geoip : bool | None ,
971+ ) -> tuple [FeatureFlag | None , str ]:
972+ """
973+ Calls /decide and returns the flag details and request id
974+ """
975+ resp_data = self .get_decide (distinct_id , groups , person_properties , group_properties , disable_geoip )
976+ request_id = resp_data .get ("requestId" )
977+ flags = resp_data .get ("flags" )
978+ flag_details = flags .get (key )
979+ return flag_details , request_id
980+
974981 def _capture_feature_flag_called (
975982 self ,
976983 distinct_id : str ,
@@ -1006,7 +1013,7 @@ def _capture_feature_flag_called(
10061013 properties ["$feature_flag_version" ] = flag_details .metadata .version
10071014 if flag_details .metadata .id :
10081015 properties ["$feature_flag_id" ] = flag_details .metadata .id
1009-
1016+
10101017 self .capture (
10111018 distinct_id ,
10121019 "$feature_flag_called" ,
0 commit comments