get_or_create for lesson documentations and personal notes doesn't work correctly because of missing unique index
Opening a single lesson (or event or extra lesson) often causes an Internal Server Error. Internally, using get_or_create sometimes raise a MultipleObjectsReturned
exception. The reasons for this behavior are described here:
- https://stackoverflow.com/a/29521117
- https://adriennedomingus.com/blog/the-perils-of-getorcreate-race-conditions
A working solution is adding an unique index for the fields lesson_period
, week
, year
, event
and extra_lesson
. This combination will always be unique.