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): Guard for nil iteration_count when updating survey iterations #23917

Merged
merged 10 commits into from
Jul 23, 2024

Conversation

Phanatic
Copy link
Contributor

Problem

fixes https://posthog.sentry.io/issues/5512240918/events/956d5e7ba790487ebe731103ba98f934/?project=1899813&statsPeriod=14d

Changes

We weren't guarding for a nil iteration_count when the current_iteration was > 0.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

Yes

How did you test this code?

Automated tests

@Phanatic Phanatic changed the title fix(Surveys) guard for nil iteration_count when updating survey iterations fix(Surveys): Guard for nil iteration_count when updating survey iterations Jul 23, 2024
@Phanatic Phanatic requested a review from a team July 23, 2024 16:15
@Phanatic Phanatic enabled auto-merge (squash) July 23, 2024 16:34
Comment on lines +383 to +385
instance.current_iteration is not None
and iteration_count is not None
and instance.current_iteration > iteration_count > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, so this was the fix I was going to go with, but the reason I didn't just fix this myself is because this doesn't tell me why these illegal states are possible? Like, if we have a situation where we have a current_iteration but no iteration_count, isn't that something we should make impossible or force-correct? can you tell me more about how this state could be reached?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an invalid state, where the survey previously had recurrence set on it and went to current_iteration of 2.
Then recurrence was disabled and customer tried to set it to be recurring again. Let me write a test for the full scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -2346,6 +2346,18 @@ def test_cannot_reduce_iterations_lt_current_iteration(self):
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json()["detail"] == "Cannot change survey recurrence to 1, should be at least 2"

def test_guards_for_nil_iteration_count(self):
survey = self._create_recurring_survey()
Copy link
Contributor

Choose a reason for hiding this comment

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

this creates a survey with an iteration count, though, right? Shouldn't our test handle the case where we don't have an iteration count and we confirm that the API doesn't fail, since that was the case that failed in production?

Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

hell yeah let's gooo

@Phanatic Phanatic merged commit 9ee8309 into master Jul 23, 2024
84 checks passed
@Phanatic Phanatic deleted the fix-none-comparision branch July 23, 2024 22:36
thmsobrmlr pushed a commit that referenced this pull request Jul 25, 2024
…ations (#23917)

We weren't guarding for a nil iteration_count when the current_iteration was > 0.
silentninja pushed a commit to silentninja/posthog that referenced this pull request Aug 8, 2024
…ations (PostHog#23917)

We weren't guarding for a nil iteration_count when the current_iteration was > 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants