-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(flags): Make sure regex matching matches strings (#20557)
- Loading branch information
1 parent
a85b806
commit eca7028
Showing
5 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,6 +255,112 @@ | |
AND "posthog_person"."team_id" = 2) | ||
''' | ||
# --- | ||
# name: TestFeatureFlagMatcher.test_invalid_regex_match_flag | ||
''' | ||
SELECT "posthog_team"."id", | ||
"posthog_team"."uuid", | ||
"posthog_team"."organization_id", | ||
"posthog_team"."api_token", | ||
"posthog_team"."app_urls", | ||
"posthog_team"."name", | ||
"posthog_team"."slack_incoming_webhook", | ||
"posthog_team"."created_at", | ||
"posthog_team"."updated_at", | ||
"posthog_team"."anonymize_ips", | ||
"posthog_team"."completed_snippet_onboarding", | ||
"posthog_team"."has_completed_onboarding_for", | ||
"posthog_team"."ingested_event", | ||
"posthog_team"."autocapture_opt_out", | ||
"posthog_team"."autocapture_exceptions_opt_in", | ||
"posthog_team"."autocapture_exceptions_errors_to_ignore", | ||
"posthog_team"."session_recording_opt_in", | ||
"posthog_team"."session_recording_sample_rate", | ||
"posthog_team"."session_recording_minimum_duration_milliseconds", | ||
"posthog_team"."session_recording_linked_flag", | ||
"posthog_team"."session_recording_network_payload_capture_config", | ||
"posthog_team"."session_replay_config", | ||
"posthog_team"."capture_console_log_opt_in", | ||
"posthog_team"."capture_performance_opt_in", | ||
"posthog_team"."surveys_opt_in", | ||
"posthog_team"."session_recording_version", | ||
"posthog_team"."signup_token", | ||
"posthog_team"."is_demo", | ||
"posthog_team"."access_control", | ||
"posthog_team"."week_start_day", | ||
"posthog_team"."inject_web_apps", | ||
"posthog_team"."test_account_filters", | ||
"posthog_team"."test_account_filters_default_checked", | ||
"posthog_team"."path_cleaning_filters", | ||
"posthog_team"."timezone", | ||
"posthog_team"."data_attributes", | ||
"posthog_team"."person_display_name_properties", | ||
"posthog_team"."live_events_columns", | ||
"posthog_team"."recording_domains", | ||
"posthog_team"."primary_dashboard_id", | ||
"posthog_team"."extra_settings", | ||
"posthog_team"."correlation_config", | ||
"posthog_team"."session_recording_retention_period_days", | ||
"posthog_team"."plugins_opt_in", | ||
"posthog_team"."opt_out_capture", | ||
"posthog_team"."event_names", | ||
"posthog_team"."event_names_with_usage", | ||
"posthog_team"."event_properties", | ||
"posthog_team"."event_properties_with_usage", | ||
"posthog_team"."event_properties_numerical", | ||
"posthog_team"."external_data_workspace_id", | ||
"posthog_team"."external_data_workspace_last_synced_at" | ||
FROM "posthog_team" | ||
WHERE "posthog_team"."id" = 2 | ||
LIMIT 21 | ||
''' | ||
# --- | ||
# name: TestFeatureFlagMatcher.test_invalid_regex_match_flag.1 | ||
''' | ||
SELECT "posthog_featureflag"."id", | ||
"posthog_featureflag"."key", | ||
"posthog_featureflag"."name", | ||
"posthog_featureflag"."filters", | ||
"posthog_featureflag"."rollout_percentage", | ||
"posthog_featureflag"."team_id", | ||
"posthog_featureflag"."created_by_id", | ||
"posthog_featureflag"."created_at", | ||
"posthog_featureflag"."deleted", | ||
"posthog_featureflag"."active", | ||
"posthog_featureflag"."rollback_conditions", | ||
"posthog_featureflag"."performed_rollback", | ||
"posthog_featureflag"."ensure_experience_continuity", | ||
"posthog_featureflag"."usage_dashboard_id", | ||
"posthog_featureflag"."has_enriched_analytics" | ||
FROM "posthog_featureflag" | ||
WHERE ("posthog_featureflag"."active" | ||
AND NOT "posthog_featureflag"."deleted" | ||
AND "posthog_featureflag"."team_id" = 2) | ||
''' | ||
# --- | ||
# name: TestFeatureFlagMatcher.test_invalid_regex_match_flag.2 | ||
''' | ||
SELECT (("posthog_person"."properties" ->> 'email')::text ~ '["[email protected]"]' | ||
AND "posthog_person"."properties" ? 'email' | ||
AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0" | ||
FROM "posthog_person" | ||
INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") | ||
WHERE ("posthog_persondistinctid"."distinct_id" = '307' | ||
AND "posthog_persondistinctid"."team_id" = 2 | ||
AND "posthog_person"."team_id" = 2) | ||
''' | ||
# --- | ||
# name: TestFeatureFlagMatcher.test_invalid_regex_match_flag.3 | ||
''' | ||
SELECT (("posthog_person"."properties" ->> 'email')::text ~ '["[email protected]"]' | ||
AND "posthog_person"."properties" ? 'email' | ||
AND NOT (("posthog_person"."properties" -> 'email') = 'null')) AS "flag_X_condition_0" | ||
FROM "posthog_person" | ||
INNER JOIN "posthog_persondistinctid" ON ("posthog_person"."id" = "posthog_persondistinctid"."person_id") | ||
WHERE ("posthog_persondistinctid"."distinct_id" = 'another_id' | ||
AND "posthog_persondistinctid"."team_id" = 2 | ||
AND "posthog_person"."team_id" = 2) | ||
''' | ||
# --- | ||
# name: TestFeatureFlagMatcher.test_multiple_flags | ||
''' | ||
SELECT "posthog_grouptypemapping"."id", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -763,6 +763,40 @@ def test_blank_flag(self): | |
FeatureFlagMatch(True, None, FeatureFlagMatchReason.CONDITION_MATCH, 0), | ||
) | ||
|
||
@snapshot_postgres_queries | ||
def test_invalid_regex_match_flag(self): | ||
Person.objects.create( | ||
team=self.team, | ||
distinct_ids=["307"], | ||
properties={ | ||
"email": '"[email protected]"', | ||
}, | ||
) | ||
feature_flag = self.create_feature_flag( | ||
filters={ | ||
"groups": [ | ||
{ | ||
"properties": [ | ||
{ | ||
"key": "email", | ||
"value": '["[email protected]"]', | ||
"operator": "regex", | ||
"type": "person", | ||
} | ||
] | ||
} | ||
] | ||
} | ||
) | ||
self.assertEqual( | ||
FeatureFlagMatcher([feature_flag], "307").get_match(feature_flag), | ||
FeatureFlagMatch(True, None, FeatureFlagMatchReason.CONDITION_MATCH, 0), | ||
) | ||
self.assertEqual( | ||
FeatureFlagMatcher([feature_flag], "another_id").get_match(feature_flag), | ||
FeatureFlagMatch(False, None, FeatureFlagMatchReason.NO_CONDITION_MATCH, 0), | ||
) | ||
|
||
def test_coercion_of_strings_and_numbers(self): | ||
Person.objects.create( | ||
team=self.team, | ||
|