Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: surveys validate conditions #28711

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions posthog/api/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,23 @@ def validate_conditions(self, value):
if value is None:
return value
Comment on lines 211 to 212
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this makes the return type dict | None


actions = value.get("actions")
if not isinstance(value, dict):
raise serializers.ValidationError("Conditions must be an object")

actions = value.get("actions", None)

if actions is None:
return value

values = actions.get("values")
values = actions.get("values", None)
if values is None or len(values) == 0:
return value

action_ids = (value.get("id") for value in values)
action_ids = [value.get("id") for value in values if isinstance(value, dict) and "id" in value]

if len(action_ids) == 0:
return value

project_actions = Action.objects.filter(team__project_id=self.context["project_id"], id__in=action_ids)

for project_action in project_actions:
Expand Down Expand Up @@ -755,7 +763,7 @@ def summarize_responses(self, request: request.Request, **kwargs):

survey = self.get_object()

cache_key = f'summarize_survey_responses_{self.team.pk}_{self.kwargs["pk"]}'
cache_key = f"summarize_survey_responses_{self.team.pk}_{self.kwargs['pk']}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit linter did that so I guess its safe

# Check if the response is cached
cached_response = cache.get(cache_key)
if cached_response is not None:
Expand Down
Loading