Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-88336

Cloud Space import fails with "duplicate key value violates unique constraint "u2c_relation_unique""

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Low
    • None
    • 8.3.0, 7.19.9
    • None

    Description

      Issue Summary

      When importing a Confluence Cloud space to On-Prem, the space import fails with the following error:

      Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "u2c_relation_unique"
        Detail: Key (targetcontentid, sourceuser, relationname)=(xxxxxxx, xxxxxxxxxxxxxxxxxxx, collaborator) already exists.
      

      This is reproducible on Data Center: yes

      Steps to Reproduce

      Confluence Cloud

      1. Create two users on Confluence Cloud with email addresses abc@mail.com and def@mail.com
      2. Have both users modify the same content
      3. Export the Confluence Cloud space

      Confluence On-Prem

      1. Have two users from two different directories (e.g. Confluence Internal Directory and AD/LDAP) with the same username (e.g. user1) but with different email addresses in both directories
        Email addresses should match the email address of the users in Confluence Cloud
      2. Perform the space import

      Expected Results

      Space Import is successful

      Actual Results

      Import fails with the following error

      2023-07-05 07:35:45,740 ERROR [Long running task: Importing data] [confluence.importexport.actions.ImportLongRunningTask] runInternal Failure during import
       -- url: /confluence/admin/restore.action | userName: admin | action: restore | referer: https://linux-45853.prod.atl-cd.net/confluence/admin/backup.action | traceId: 22bb5a5608e1dd1f
      com.atlassian.confluence.importexport.ImportExportException: com.atlassian.confluence.importexport.ImportExportException: Unable to complete import: Error while importing backup: org.hibernate.exception.ConstraintViolationException: could not execute statement
      	at com.atlassian.confluence.importexport.xmlimport.BackupImporter.importEntities(BackupImporter.java:431)
      	at com.atlassian.confluence.importexport.xmlimport.BackupImporter.importEverything(BackupImporter.java:392)
      	at com.atlassian.confluence.importexport.xmlimport.FileBackupImporter.importEverything(FileBackupImporter.java:172)
      	at com.atlassian.confluence.importexport.xmlimport.BackupImporter$1.doInTransactionWithoutResult(BackupImporter.java:284)
      ...
      Caused by: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "u2c_relation_unique"
        Detail: Key (targetcontentid, sourceuser, relationname)=(2457636, 2cb280848924dc26018924f0737f0000, collaborator) already exists.
      	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2676)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
      	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:356)
      	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:496)
      	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:413)
      	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:190)
      	at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:152)
      

      This happens if both user accounts (two different email addresses) on Confluence Cloud share the same username on Confluence On-Prem.

      Workaround

      1. Rename the username for one of the account; OR
      2. Delete one of the duplicate account that is no longer needed

      Diagnosis

      Run the SQL verify if the affected userKey from the logs has two records with the same username but different email addresses

      select cu.user_name, cu.email_address, cu.active, cu.directory_id from cwd_user cu
      inner join user_mapping um on um.username = cu.user_name
      where um.user_key = '<userKey>'
      

      To verify if there are many users that might be impacted by this, you can run the SQL query below:

      select user_name, email_address, active, directory_id from cwd_user cu
      where cu.user_name in (
      select user_name from cwd_user
      group by user_name
      having count(user_name) > 1);
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              c84ad05f80fa Puven Mannen
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: