diff --git a/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr b/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr index 2bce2f52b4920..1808327312911 100644 --- a/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr +++ b/posthog/api/test/__snapshots__/test_organization_feature_flag.ambr @@ -1525,7 +1525,8 @@ "posthog_survey"."start_date", "posthog_survey"."end_date", "posthog_survey"."updated_at", - "posthog_survey"."archived" + "posthog_survey"."archived", + "posthog_survey"."responses_limit" FROM "posthog_survey" WHERE "posthog_survey"."linked_flag_id" = 2 ''' diff --git a/posthog/api/test/__snapshots__/test_survey.ambr b/posthog/api/test/__snapshots__/test_survey.ambr index 6798d297f4652..d3636169bb801 100644 --- a/posthog/api/test/__snapshots__/test_survey.ambr +++ b/posthog/api/test/__snapshots__/test_survey.ambr @@ -180,6 +180,7 @@ "posthog_survey"."end_date", "posthog_survey"."updated_at", "posthog_survey"."archived", + "posthog_survey"."responses_limit", "posthog_featureflag"."id", "posthog_featureflag"."key", "posthog_featureflag"."name", diff --git a/posthog/api/test/test_survey.py b/posthog/api/test/test_survey.py index 9ef7622f344f9..d37dc40e33889 100644 --- a/posthog/api/test/test_survey.py +++ b/posthog/api/test/test_survey.py @@ -853,6 +853,7 @@ def test_can_list_surveys(self): "archived": False, "start_date": None, "end_date": None, + "responses_limit": None, } ], } diff --git a/posthog/tasks/stop_surveys_reached_target.py b/posthog/tasks/stop_surveys_reached_target.py index 0a9931cf9e57f..f95a1082c15d1 100644 --- a/posthog/tasks/stop_surveys_reached_target.py +++ b/posthog/tasks/stop_surveys_reached_target.py @@ -46,10 +46,9 @@ def stop_surveys_reached_target() -> None: all_surveys = Survey.objects.exclude(responses_limit__isnull=True).only( "id", "responses_limit", "team_id", "created_at" ) - if not all_surveys: - return - for team_id, team_surveys in groupby(all_surveys, lambda survey: survey.team_id): + all_surveys_sorted = sorted(all_surveys, key=lambda survey: survey.team_id) + for team_id, team_surveys in groupby(all_surveys_sorted, lambda survey: survey.team_id): team_surveys_list = list(team_surveys) surveys_ids = [survey.id for survey in team_surveys_list] earliest_survey_start_date = min([survey.created_at for survey in team_surveys_list]) diff --git a/posthog/tasks/test/test_stop_surveys_reached_target.py b/posthog/tasks/test/test_stop_surveys_reached_target.py index 617e966106f0c..f2c0b52566cde 100644 --- a/posthog/tasks/test/test_stop_surveys_reached_target.py +++ b/posthog/tasks/test/test_stop_surveys_reached_target.py @@ -42,7 +42,7 @@ def test_stop_surveys_with_enough_responses(self) -> None: created_by=self.user, linked_flag=self.flag, responses_limit=1, - created_at=now() - relativedelta(hours=12), + created_at=now(), ), Survey.objects.create( name="2", @@ -50,7 +50,7 @@ def test_stop_surveys_with_enough_responses(self) -> None: created_by=self.user, linked_flag=self.flag, responses_limit=1, - created_at=now() - relativedelta(hours=12), + created_at=now(), ), Survey.objects.create( name="3", @@ -58,7 +58,7 @@ def test_stop_surveys_with_enough_responses(self) -> None: created_by=self.user, linked_flag=self.flag, responses_limit=1, - created_at=now() - relativedelta(hours=12), + created_at=now(), ), ]