Исчезает вновь созданный объект модели Django из обработчика сигнала pre_save

In our Django app, in order to prevent users from randomly updating their profiles for compliance purposes, we need all profile updates to be reviewed. I added a pre_save signal to the User model and in the signal handler, I create an object to the table ProfileUpdateRequest using ProfileUpdateRequest.objects.create(...) and then raise an exception. The exception is then caught in the ViewSet to return a proper response.

However, when I tested it, I found that every time I update the user profile, a new object of ProfileUpdateRequest was created but not applied to the database. I assigned the returned value of the create() method to a variable and logged it out. I saw the id of the new object increasing all the time, but there was no new object added to the table at all.

Интересно, не были ли изменения применены к БД немедленно, а исключение нарушило нормальный рабочий процесс, из-за чего изменения не были применены к БД.

Вернуться на верх