Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-64802

CSV import changes project of moved issues back to the original creating duplicate issues and IllegalArgumentException

    XMLWordPrintable

Details

    Description

      Summary

      When using a CSV import that includes an issue that was moved from one project to another at some point, it incorrectly updates the project of the issue back to the original one causing duplicate issue Keys and viewing the issue is no longer possible.

      Steps to Reproduce

      1. Import or create an issue, for example MWK-1.
      2. Move issue to another project, in this example it becomes TECH-2. This can also involve changing things such as version and component, which are project-specific.
      3. CSV import the issue to update any field value.

      Expected Results

      The TECH-2 issue is updated, using the data from MWK-1 (it will correctly find the issue using the moved_issue_key table).

      Actual Results

      The issue key is moved back to the old project - for example TECH-2 is moved into the MWK project, and keeps the correct issuenum (3). Additionally, the below exception is thrown when attempting to view MWK-1, and TECH-2 will 404.

      java.lang.IllegalArgumentException: Passed List had more than one value.
      	at org.ofbiz.core.entity.EntityUtil.getOnly(EntityUtil.java:62) [entityengine-1.2.3.jar:?]
      	at com.atlassian.jira.issue.managers.DefaultIssueManager$IssueFinder.getIssueFromIssueEntityByProjectAndNumber(DefaultIssueManager.java:986) [DefaultIssueManager$IssueFinder.class:?]
      	at com.atlassian.jira.issue.managers.DefaultIssueManager$IssueFinder.getIssueFromIssueEntity(DefaultIssueManager.java:982) [DefaultIssueManager$IssueFinder.class:?]
      	at com.atlassian.jira.issue.managers.DefaultIssueManager$IssueFinder.getIssue(DefaultIssueManager.java:959) [DefaultIssueManager$IssueFinder.class:?]
      	at com.atlassian.jira.issue.managers.DefaultIssueManager.getIssue(DefaultIssueManager.java:140) [DefaultIssueManager.class:?]
      	at com.atlassian.jira.issue.managers.DefaultIssueManager.getIssueObject(DefaultIssueManager.java:340) [DefaultIssueManager.class:?]
      	at com.atlassian.jira.bc.issue.DefaultIssueService.getIssue(DefaultIssueService.java:170) [DefaultIssueService.class:?]
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [?:1.8.0_20]
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [?:1.8.0_20]
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [?:1.8.0_20]
      	at java.lang.reflect.Method.invoke(Method.java:483) [?:1.8.0_20]
      

      See [^full_stack_trace] for more info.

      Notes

      Looking into the database we can see the problem is the project key is changed back to what it was. Prior to the import:

      select * from jiraissue;
        id   | pkey | issuenum | project | reporter | assignee | creator | issuetype | summary | description | environment | priority | resolution
      -------+------+----------+---------+----------+----------+---------+-----------+---------+-------------+-------------+----------+------------
       10000 |      |        1 |   10001 | admin    |          | admin   | 10005     | 1       |             |             | 3        |
       10002 |      |        2 |   10000 | admin    |          | admin   | 10001     | 2       |             |             | 3        |
       10003 |      |        3 |   10000 | admin    |          | admin   | 10001     | 3       |             |             | 3        |
       10001 |      |        2 |   10001 | admin    |          | admin   | 10005     | 1       |             |             | 3        |
      (4 rows)
      

      And after:

      select * from jiraissue;
        id   | pkey | issuenum | project | reporter | assignee | creator | issuetype | summary | description | environment | priority | resolution
      -------+------+----------+---------+----------+----------+---------+-----------+---------+-------------+-------------+----------+------------
       10000 |      |        1 |   10001 | admin    |          | admin   | 10005     | 1       |             |             | 3        |
       10002 |      |        2 |   10000 | admin    |          | admin   | 10001     | 2       |             |             | 3        |
       10003 |      |        3 |   10000 | admin    |          | admin   | 10001     | 3       |             |             | 3        |
       10001 |      |        2 |   10000 | admin    |          | admin   | 10001     | test    |             |             | 3        |
      (4 rows)
      

      The moved_issue_key table is not updated:

      select * from moved_issue_key ;
        id   | old_issue_key | issue_id
      -------+---------------+----------
       10000 | MWK-1         |    10001
      (1 row)
      

      To check if you are affected:

      Find duplicates by running:

      SELECT i.id, (p.pkey || '-' ||  i.issuenum) AS issuekey, i.creator, i.created, i.summary from jiraissue i join project p  on i.project = p.id where (p.pkey || '-' ||  i.issuenum) = (SELECT (p.pkey || '-' ||  i.issuenum) from jiraissue i join project p  on i.project = p.id group by (p.pkey || '-' ||  i.issuenum) having count(1) > 1);
      

      Workaround

      The issue cannot be accessed to be moved, unless through bulk edit. Then when moving the issue back to TECH, it will create a new issue key (such as TECH-3). MWK-1 will then not redirect to TECH-3 and anything linked to TECH-2 will break. As such a SQL update is needed. For example:

      1. Stop JIRA.
      2. Find the project were the issue was moved to by searching the history, replacing <issue_id> with the ids from the search to find duplicates:
        select * from changeitem ci join changegroup cg on cg.id = ci.groupid where ci.field = 'project' and cg.issueid = <issue_id>;
        
        Example result:
          id   | groupid | fieldtype |  field  | oldvalue |  oldstring  | newvalue |  newstring  |  id   | issueid |  author  |          created
        -------+---------+-----------+---------+----------+-------------+----------+-------------+-------+---------+----------+----------------------------
         40200 |   36300 | jira      | project | 10000    | OLD Project | 10500    | New Project | 36300 |   16115 | sysadmin | 2016-03-15 16:51:31.838-04
        (1 row)
        
      3. Get the "newvalue". It corresponds to the project it was moved to.
      4. Update the issue to have the correct project:
        update jiraissue set project = <newvalue> where id = <issue_id>
        
      5. Start JIRA and reindex.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Anonymous Anonymous
              Votes:
              22 Vote for this issue
              Watchers:
              23 Start watching this issue

              Dates

                Created:
                Updated: