Display name already exists - bug with editing profile
Steps to reproduce:
- Create an account
- Go to edit profile
- Add a profile picture and try to save
- You should get this empty error message (not cool that it is empty by the way):
Django error logs:
[...]
codabench-django-1 | return executor(sql, params, many, context)
codabench-django-1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
codabench-django-1 | return self.cursor.execute(sql, params)
codabench-django-1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 89, in __exit__
codabench-django-1 | raise dj_exc_value.with_traceback(traceback) from exc_value
codabench-django-1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
codabench-django-1 | return self.cursor.execute(sql, params)
codabench-django-1 | django.db.utils.IntegrityError: duplicate key value violates unique constraint "profiles_user_display_name_key"
codabench-django-1 | DETAIL: Key (display_name)=() already exists.
The error log suggests that there is a unique constraint on the display_name
field in the database schema, and the code is attempting to insert or update a record that would cause this constraint to be violated. Specifically, the error suggests that a record with an empty display name (display_name=()
) already exists, and another record with an empty display name is being attempted to be saved.
Indeed, if you fill in the display name then you can save without problems.
Why is the unique constraint that is violated? Updating the display name, even with an empty field, should not duplicate the entry. Just update it, or do nothing.
I confirm that the problem happens anytime you try to save an empty "Display name". As it if was a not-null constraint instead of a unique constraint.