Skip to content

Commit

Permalink
fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajmajerik committed Oct 17, 2024
1 parent 67c741d commit f0bc34a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ def _validate_event_variants(self, funnel_results: FunnelsQueryResponse):
eventsWithOrderZero = []
for eventArr in funnel_results.results:
for event in eventArr:
if event.get("order") == 0:
eventsWithOrderZero.append(event)
event_dict = cast(dict[str, Any], event)
if event_dict.get("order") == 0:
eventsWithOrderZero.append(event_dict)

# Check if "control" is present
for event in eventsWithOrderZero:
event_variant = event.get("breakdown_value")[0]
event_variant = event.get("breakdown_value", [None])[0]
if event_variant == "control":
errors[ExperimentNoResultsErrorKeys.NO_CONTROL_VARIANT] = False
errors[ExperimentNoResultsErrorKeys.NO_FLAG_INFO] = False
Expand All @@ -166,7 +167,7 @@ def _validate_event_variants(self, funnel_results: FunnelsQueryResponse):
# Check if at least one of the test variants is present
test_variants = [variant for variant in self.variants if variant != "control"]
for event in eventsWithOrderZero:
event_variant = event.get("breakdown_value")[0]
event_variant = event.get("breakdown_value", [None])[0]
if event_variant in test_variants:
errors[ExperimentNoResultsErrorKeys.NO_TEST_VARIANT] = False
errors[ExperimentNoResultsErrorKeys.NO_FLAG_INFO] = False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import cast
from posthog.hogql_queries.experiments.experiment_funnel_query_runner import ExperimentFunnelQueryRunner
from posthog.models.experiment import Experiment
from posthog.models.feature_flag.feature_flag import FeatureFlag
Expand Down Expand Up @@ -227,7 +228,7 @@ def test_validate_event_variants_no_events(self):
ExperimentNoResultsErrorKeys.NO_TEST_VARIANT: True,
}
)
self.assertEqual(context.exception.detail[0], expected_errors)
self.assertEqual(cast(list, context.exception.detail)[0], expected_errors)

@freeze_time("2020-01-01T12:00:00Z")
def test_validate_event_variants_no_control(self):
Expand Down Expand Up @@ -269,7 +270,7 @@ def test_validate_event_variants_no_control(self):
ExperimentNoResultsErrorKeys.NO_TEST_VARIANT: False,
}
)
self.assertEqual(context.exception.detail[0], expected_errors)
self.assertEqual(cast(list, context.exception.detail)[0], expected_errors)

@freeze_time("2020-01-01T12:00:00Z")
def test_validate_event_variants_no_test(self):
Expand Down Expand Up @@ -311,7 +312,7 @@ def test_validate_event_variants_no_test(self):
ExperimentNoResultsErrorKeys.NO_TEST_VARIANT: True,
}
)
self.assertEqual(context.exception.detail[0], expected_errors)
self.assertEqual(cast(list, context.exception.detail)[0], expected_errors)

@freeze_time("2020-01-01T12:00:00Z")
def test_validate_event_variants_no_flag_info(self):
Expand Down Expand Up @@ -355,4 +356,4 @@ def test_validate_event_variants_no_flag_info(self):
ExperimentNoResultsErrorKeys.NO_TEST_VARIANT: True,
}
)
self.assertEqual(context.exception.detail[0], expected_errors)
self.assertEqual(cast(list, context.exception.detail)[0], expected_errors)

0 comments on commit f0bc34a

Please sign in to comment.