Context
PR #577 added the JSON Schema validation infrastructure (survey/schema.py, Survey.response_schema, SurveyResponse.clean()) but intentionally did not wire it into the live submission path. The service layer still uses SurveyResponse.objects.create() which skips full_clean(), so validation is not yet enforced on new responses.
The plan is to run python manage.py validate_responses on production data first to confirm clean baseline, then activate per-submission validation in this follow-up.
Work required
-
Activate validation on submit: Update survey/services/survey.py to delegate to the model method (which calls full_clean()):
# survey/services/survey.py
def accept_response(self, survey: Survey, responseValues):
survey.accept_response(responseValues) # delegates to Survey.accept_response() which calls full_clean()
-
Cache the schema: Change Survey.response_schema from @property to @cached_property so the JSON Schema is built once per instance rather than on every validation call.
from django.utils.functional import cached_property
@cached_property
def response_schema(self) -> dict:
...
-
Update validate_responses output: Use ', '.join(exc.messages) instead of exc.message in the management command to handle multi-error ValidationError correctly.
Prerequisites
References
Context
PR #577 added the JSON Schema validation infrastructure (
survey/schema.py,Survey.response_schema,SurveyResponse.clean()) but intentionally did not wire it into the live submission path. The service layer still usesSurveyResponse.objects.create()which skipsfull_clean(), so validation is not yet enforced on new responses.The plan is to run
python manage.py validate_responseson production data first to confirm clean baseline, then activate per-submission validation in this follow-up.Work required
Activate validation on submit: Update
survey/services/survey.pyto delegate to the model method (which callsfull_clean()):Cache the schema: Change
Survey.response_schemafrom@propertyto@cached_propertyso the JSON Schema is built once per instance rather than on every validation call.Update
validate_responsesoutput: Use', '.join(exc.messages)instead ofexc.messagein the management command to handle multi-errorValidationErrorcorrectly.Prerequisites
python manage.py validate_responseson production and confirm 0 errorsReferences