@@ -1355,6 +1355,77 @@ def test_feature_flags_local_evaluation_for_negated_cohorts(
13551355 self .assertEqual (patch_flags .call_count , 0 )
13561356 self .assertEqual (patch_get .call_count , 0 )
13571357
1358+ @mock .patch ("posthog.feature_flags.log" )
1359+ @mock .patch ("posthog.client.flags" )
1360+ @mock .patch ("posthog.client.get" )
1361+ def test_feature_flags_with_flag_dependencies (
1362+ self , patch_get , patch_flags , mock_log
1363+ ):
1364+ client = Client (FAKE_TEST_API_KEY , personal_api_key = FAKE_TEST_API_KEY )
1365+ client .feature_flags = [
1366+ {
1367+ "id" : 1 ,
1368+ "name" : "Flag with Dependencies" ,
1369+ "key" : "flag-with-dependencies" ,
1370+ "active" : True ,
1371+ "filters" : {
1372+ "groups" : [
1373+ {
1374+ "properties" : [
1375+ {
1376+ "key" : "beta-feature" ,
1377+ "operator" : "exact" ,
1378+ "value" : True ,
1379+ "type" : "flag" ,
1380+ },
1381+ {
1382+ "key" : "email" ,
1383+ "operator" : "icontains" ,
1384+ "value" : "@example.com" ,
1385+ "type" : "person" ,
1386+ },
1387+ ],
1388+ "rollout_percentage" : 100 ,
1389+ }
1390+ ],
1391+ },
1392+ }
1393+ ]
1394+
1395+ # Test that flag evaluation doesn't fail when encountering a flag dependency
1396+ # The flag should evaluate based on other conditions (email contains @example.com)
1397+ # Since flag dependencies aren't implemented, it should skip the flag condition
1398+ # and evaluate based on the email condition only
1399+ feature_flag_match = client .get_feature_flag (
1400+ "flag-with-dependencies" ,
1401+ "test-user" ,
1402+ person_properties = {
"email" :
"[email protected] " },
1403+ )
1404+ self .assertEqual (feature_flag_match , True )
1405+ self .assertEqual (patch_flags .call_count , 0 )
1406+ self .assertEqual (patch_get .call_count , 0 )
1407+
1408+ # Verify warning was logged for flag dependency
1409+ mock_log .warning .assert_called_with (
1410+ "Flag dependency filters are not supported in local evaluation. "
1411+ "Skipping condition for flag '%s' with dependency on flag '%s'" ,
1412+ "flag-with-dependencies" ,
1413+ "beta-feature" ,
1414+ )
1415+
1416+ # Test with email that doesn't match
1417+ feature_flag_match = client .get_feature_flag (
1418+ "flag-with-dependencies" ,
1419+ "test-user-2" ,
1420+ person_properties = {
"email" :
"[email protected] " },
1421+ )
1422+ self .assertEqual (feature_flag_match , False )
1423+ self .assertEqual (patch_flags .call_count , 0 )
1424+ self .assertEqual (patch_get .call_count , 0 )
1425+
1426+ # Verify warning was logged again for the second evaluation
1427+ self .assertEqual (mock_log .warning .call_count , 2 )
1428+
13581429 @mock .patch ("posthog.client.Poller" )
13591430 @mock .patch ("posthog.client.get" )
13601431 def test_load_feature_flags (self , patch_get , patch_poll ):
0 commit comments