Issue Summary
It's currently possible to synchronise users when their username ends with a space. Therefore, it makes it possible for these 2 users to exist in Confluence:
- "admin" - (no space at the end)
- "admin " - (with a space at the end)
This is detected as 2 different users in Confluence and both users will have separate records in the cwd_user and user_mapping table.
If you export the site to XML and attempt to re-import it later, the import will fail due to a unique constraint violation.
Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "unq_lwr_username"
Detail: Key (lower_username)=(admin) already exists.
The import process in Confluence strips the space at the end of the username, which results in Confluence attempting to insert the same username into the user_mapping table twice.
Steps to Reproduce
- Synchronise 2 users to Confluence with identical usernames but one of them has a space at the end of their username.
- Export the site to XML.
- Create a new instance of the same version.
- Import the XML backup.
Expected Results
The XML restoration should succeed with no errors.
Actual Results
The XML restoration fails with the below exception thrown in the atlassian-confluence.log file:
2021-11-12 11:03:38,069 ERROR [Long running task: Importing data] [confluence.importexport.xmlimport.BackupImporter] importEntities Cannot import the entities:
-- url: /longrunningtaskxml.action | referer: http:com.atlassian.confluence.importexport.ImportExportException: Unable to complete import because the data does not match the constraints in the Confluence schema. Cause: PSQLException: ERROR: duplicate key value violates unique constraint "unq_lwr_username"
Detail: Key (lower_username)=(admin) already exists.
Workaround
Ensure each user's username in Confluence is unique and not differentiated via a space character at the end of their username.