Feature #22701

Allow forward reference to parent when importing issues

Added by Gregor Schmidt about 1 year ago. Updated 5 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:


Target version:3.4.0


When importing issues via CSV with parent relations, the parent issues need to be positioned before child issues. Otherwise the relation will be ignored.

To work around this limitation, the issue import could be extended to use multiple passes:

  1. one to import basic issue properties
  2. one to import relations to other issues

This way it becomes easier to create the CSV files for imports, since order is no longer important.

This change would also be a prerequisite to import general issue relations. Since those cannot be more complex that parent relations and cannot necessarily be linearized properly.

Attached you find a patch series based on trunk r15361.

While implemented the changes, I tried to keep the Import free from issue related information. Other existing Import sub classes - within plugins e.g. - should need as little updates as possible.

0001 Extend test data for issue import

This change adds two rows to the existing issue import fixture file. These rows contain a parent and a child issue, while the parent is placed after the child. This would not import properly given the current implementation.

The patch also updates the existing tests, where the number of imported issues is asserted.

0002 Add test for issue relations to following rows

This patch extends the existing parent issue import test to also verify that the newly introduced parent child relation is properly imported. This test fails with the current implementation.

0003 Multi-pass CSV import

This patch defines a required_passes method within Import which returns 1 by default and may be overwritten in sub classes. The IssueImport does so and returns 1 if no parent_id mapping was set, otherwise it returns 2.

The run method is split into run and run_pass. The first one is recursive and called once for each pass. It also handles the max_* options. The second is only responsible for reading the rows, creating or updating the ImportItems and passing everything to build_object.

Since build_object may now be called multiple times (once for each pass), the argument list was extended to provide more context. If somebody created a custom import in a plugin, this would need to be changed by the plugin's author.

In the IssueImport, build_object is now split into build_issue and build_relations, the first is called in the first pass, the second in pass 2.

The patch also contains a migration, which adds a completed_passes field to ImportItem. This is needed to properly (re-)store progress for multi-step imports, like the ones via the web UI.

Finally the patch adds some test to make sure, that the general behavior of multi-step imports did not change with the introduction of multi-pass imports.

Disclaimer: I know, this is a rather large change to fix a minor nuisance. But as mentioned earlier, I think, this change is a necessary prerequisite to support importing "Related Issues" properly, which I would like to contribute next, if this patch is accepted.

0001-Extend-test-data-for-issue-imported.patch Magnifier (3.28 KB) Gregor Schmidt, 2016-05-02 14:52

0002-Add-test-for-issue-relations-to-following-rows.patch Magnifier (1.19 KB) Gregor Schmidt, 2016-05-02 14:52

0003-Mulit-pass-CSV-import.patch Magnifier (10.6 KB) Gregor Schmidt, 2016-05-02 14:52

Associated revisions

Revision 16241
Added by Jean-Philippe Lang 5 months ago

Allow forward reference to parent when importing issues (#22701).


#1 Updated by Jan from Planio www.plan.io about 1 year ago

  • Target version set to Candidate for next minor release

#2 Updated by Go MAEDA about 1 year ago

  • Category set to Importers
  • Target version changed from Candidate for next minor release to 3.4.0

#3 Updated by Toshi MARUYAMA about 1 year ago

  • Description updated (diff)

#4 Updated by Jean-Philippe Lang 5 months ago

  • Subject changed from Multi-Pass CSV import to improve parent issue imports to Allow forward reference to parent when importing issues
  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Feature added in r16241 using a callback mechanism instead of the more complex multi-pass solution proposed in the patch.
It can be extend easily to support issue relations in the future as well.

#5 Updated by Gregor Schmidt 5 months ago

Interesting approach. Thanks for taking care of this issue.

Also available in: Atom PDF