If you delete a question from a survey, then all participation (completed survey submission / user_input) answers to that question get deleted.
Steps to Reproduce
Super easy to reproduce. Submit completion of any survey (collect at least one participation/user_input). Then go to the survey and delete a question. Then go view the Survey Participation Result, and you'll see the question and answer are gone.
Expected behavior
If I attempt to delete a question on a survey with linked participations, I should get a ForeignKey constraint violation error.
How to fix
Navigate to surveys > models > survey_user_input.py > SurveyUserInputLine(models.Model) class > question_id
(Currently line 619)
The line for question_id property says:
question_id = fields.Many2one('survey.question', string='Question', ondelete='cascade', required=True)
This looks like a bug to me. "ondelete='cascade' means that a deletion to the question will delete all answers. This should be ondelete='restrict' so that the database refuses to delete a question that has user-submitted survey answers.
Module
Surveys (on odoo 16.0)
Describe the bug
If you delete a question from a survey, then all participation (completed survey submission / user_input) answers to that question get deleted.
Steps to Reproduce
Super easy to reproduce. Submit completion of any survey (collect at least one participation/user_input). Then go to the survey and delete a question. Then go view the Survey Participation Result, and you'll see the question and answer are gone.
Expected behavior If I attempt to delete a question on a survey with linked participations, I should get a ForeignKey constraint violation error.
How to fix
Navigate to surveys > models > survey_user_input.py > SurveyUserInputLine(models.Model) class > question_id (Currently line 619) The line for question_id property says:
question_id = fields.Many2one('survey.question', string='Question', ondelete='cascade', required=True)
This looks like a bug to me. "ondelete='cascade' means that a deletion to the question will delete all answers. This should be ondelete='restrict' so that the database refuses to delete a question that has user-submitted survey answers.