fix: Tries to fix the survey behavior - #1015
Open
AyakorK wants to merge 2 commits into
Open
Conversation
AyakorK
marked this pull request as ready for review
August 10, 2026 07:38
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎩 Description
Fixes duplicate answers on questionnaires that allow unregistered (non-logged-in) respondents.
The root cause was in
session_token, used to identify anonymous respondents: it readsession[:session_id], a key that is never actually assigned anywhere in the codebase. This madesession_tokenreturn the same blank value for every anonymous visitor, so different respondents became indistinguishable from one another once answers were stored/exported, which is what looked like duplicates. It now usesrequest.session.id, the actual Rails session identifier, giving each anonymous visitor a stable, unique token.On top of that:
AnswerQuestionnairenow usesfind_or_initialize_byinstead ofAnswer.new, so a resubmission for the same respondent/question updates the existing answer instead of creating a second one.uniquenessvalidation was added onAnsweras a model-level safety net against duplicates, independent of the two fixes above.UserAnswersSerializernow captures question positions once at the start of an export instead of re-reading them live per answer, to avoid inconsistent column mapping if the questionnaire structure changes mid-export.None of this changes the respondent-facing experience, same forms, same flow, just correct identification and data underneath.
There have also been separate, unconfirmed reports of answers appearing shifted/misaligned on submit and/or export. We could not pin down a cause for that with certainty. It's possible (not confirmed) that the
session_tokenfix also alleviates part of it, since before this fix, every unregistered respondent shared the same blank identifier, meaning several different people's answers could end up merged under a single respondent row in an export, which could look like misalignment. This is a plausible side-effect at best, not a verified fix for that specific report.📌 Related Issues
Tasks
surveys_controller_extends.rb: fixedsession_token/visitor_already_answered?to userequest.session.idinstead of the never-assignedsession[:session_id]answer_questionnaire_extends.rb: switched tofind_or_initialize_byinstead ofAnswer.newto make answer submission idempotentanswer_extends.rb: added auniquenessvalidation onAnsweras a model-level duplicate guarduser_answers_serializer_extends.rb: cache question positions once at the start of export instead of re-reading them live per answer