django-survey icon indicating copy to clipboard operation
django-survey copied to clipboard

cannot loaddata with choices

Open johanneswilm opened this issue 1 year ago • 2 comments

When I try to dumpdata and subsequently loaddata, I get a large amount of errors thrown. This seems to be due to choices being converted to their slug equivalent when saving to the database while the original choices values are checked for.

  File ".../python-3.11.2/lib/python3.11/site-packages/survey/models/answer.py", line 87, in check_answer_for_select
    raise ValidationError(msg)
django.core.exceptions.ValidationError: ["Impossible answer 'spiser-ikke-fisk' should be in ['Spiser ikke fisk', 'Spiser ofte fisk', 'Spiser fisk hver dag', 'Spiser overvejende fisk', 'Spiser kun fisk'] "]

johanneswilm avatar Mar 04 '23 06:03 johanneswilm

A quick fix: override https://github.com/Pierre-Sassoulas/django-survey/blob/main/survey/models/question.py#L376 to not use slugify. That way the original values are storied, not the slugified ones.

johanneswilm avatar Mar 04 '23 08:03 johanneswilm

Can you open a merge request with this fix @johanneswilm, please ? I'm not sure what tests will break but I don't remember exactly why I did that in the first place.

Pierre-Sassoulas avatar Mar 04 '23 08:03 Pierre-Sassoulas