@@ -2246,3 +2246,112 @@ def test_parse_send_feature_flags_method(self):
22462246 with self .assertRaises (TypeError ) as cm :
22472247 client ._parse_send_feature_flags (None )
22482248 self .assertIn ("Invalid type for send_feature_flags" , str (cm .exception ))
2249+
2250+ @mock .patch ("posthog.client.batch_post" )
2251+ def test_get_feature_flag_result_with_empty_string_payload (self , patch_batch_post ):
2252+ """Test that get_feature_flag_result returns a FeatureFlagResult when payload is empty string"""
2253+ client = Client (
2254+ FAKE_TEST_API_KEY ,
2255+ personal_api_key = "test_personal_api_key" ,
2256+ sync_mode = True ,
2257+ )
2258+
2259+ # Set up local evaluation with a flag that has empty string payload
2260+ client .feature_flags = [
2261+ {
2262+ "id" : 1 ,
2263+ "name" : "Test flag" ,
2264+ "key" : "test-flag" ,
2265+ "is_simple_flag" : False ,
2266+ "active" : True ,
2267+ "rollout_percentage" : None ,
2268+ "filters" : {
2269+ "groups" : [
2270+ {
2271+ "properties" : [],
2272+ "rollout_percentage" : None ,
2273+ "variant" : "empty-variant" ,
2274+ }
2275+ ],
2276+ "multivariate" : {
2277+ "variants" : [
2278+ {
2279+ "key" : "empty-variant" ,
2280+ "name" : "Empty Variant" ,
2281+ "rollout_percentage" : 100 ,
2282+ }
2283+ ]
2284+ },
2285+ "payloads" : {
2286+ "empty-variant" : "" # Empty string payload
2287+ },
2288+ },
2289+ }
2290+ ]
2291+
2292+ # Test get_feature_flag_result
2293+ result = client .get_feature_flag_result (
2294+ "test-flag" , "test-user" , only_evaluate_locally = True
2295+ )
2296+
2297+ # Should return a FeatureFlagResult, not None
2298+ self .assertIsNotNone (result )
2299+ self .assertEqual (result .key , "test-flag" )
2300+ self .assertEqual (result .get_value (), "empty-variant" )
2301+ self .assertEqual (result .payload , "" ) # Should be empty string, not None
2302+
2303+ @mock .patch ("posthog.client.batch_post" )
2304+ def test_get_all_flags_and_payloads_with_empty_string (self , patch_batch_post ):
2305+ """Test that get_all_flags_and_payloads includes flags with empty string payloads"""
2306+ client = Client (
2307+ FAKE_TEST_API_KEY ,
2308+ personal_api_key = "test_personal_api_key" ,
2309+ sync_mode = True ,
2310+ )
2311+
2312+ # Set up multiple flags with different payload types
2313+ client .feature_flags = [
2314+ {
2315+ "id" : 1 ,
2316+ "name" : "Flag with empty payload" ,
2317+ "key" : "empty-payload-flag" ,
2318+ "is_simple_flag" : False ,
2319+ "active" : True ,
2320+ "filters" : {
2321+ "groups" : [{"properties" : [], "variant" : "variant1" }],
2322+ "multivariate" : {
2323+ "variants" : [{"key" : "variant1" , "rollout_percentage" : 100 }]
2324+ },
2325+ "payloads" : {"variant1" : "" }, # Empty string
2326+ },
2327+ },
2328+ {
2329+ "id" : 2 ,
2330+ "name" : "Flag with normal payload" ,
2331+ "key" : "normal-payload-flag" ,
2332+ "is_simple_flag" : False ,
2333+ "active" : True ,
2334+ "filters" : {
2335+ "groups" : [{"properties" : [], "variant" : "variant2" }],
2336+ "multivariate" : {
2337+ "variants" : [{"key" : "variant2" , "rollout_percentage" : 100 }]
2338+ },
2339+ "payloads" : {"variant2" : "normal payload" },
2340+ },
2341+ },
2342+ ]
2343+
2344+ result = client .get_all_flags_and_payloads (
2345+ "test-user" , only_evaluate_locally = True
2346+ )
2347+
2348+ # Check that both flags are included
2349+ self .assertEqual (result ["featureFlags" ]["empty-payload-flag" ], "variant1" )
2350+ self .assertEqual (result ["featureFlags" ]["normal-payload-flag" ], "variant2" )
2351+
2352+ # Check that empty string payload is included (not filtered out)
2353+ self .assertIn ("empty-payload-flag" , result ["featureFlagPayloads" ])
2354+ self .assertEqual (result ["featureFlagPayloads" ]["empty-payload-flag" ], "" )
2355+ self .assertEqual (
2356+ result ["featureFlagPayloads" ]["normal-payload-flag" ], "normal payload"
2357+ )
0 commit comments