Prevent invalid hierarchies in converted work item moves

What does this MR do and why?

Moving an Issue with a Task child while converting the parent to Task can create destination items without their parent link, close the sources, and report success.

This MR validates the existing parent, child, and depth restrictions before move mutations, after permission checks and destination-type resolution. It uses an independent WorkItem loaded from the database, so pending edits and validation errors on the source are not changed by the hierarchy check. Moves that keep the same persisted type skip the preflight.

The update services retain only move errors across valid?, leaving ordinary updates unchanged. Errors already regenerated by model validation are not added a second time. An unrelated title edit saved before a rejected move remains saved, including the existing EE Status Page publication behavior.

The tests also cover Issue and WorkItem noteables through shared quick-action examples. Custom-type preflight coverage is split into the three requested cases without redundant provider lookups or type-internal assertions.

References

Closes #629152

Screenshots or screen recordings

Not applicable. This changes backend validation and error propagation for an existing operation, with no UI layout changes.

How to set up and validate locally

  1. Create an Issue with a Task child in a source project and a destination project where the same user can move issues.
  2. Add /move group/destination-project [type:Task] to a note on the Issue.
  3. Check that the hierarchy error is reported, both source items remain open and unmoved, the original parent link remains, and no destination items or move system notes are created.
  4. Repeat with a compatible destination type, such as Incident. Check that the destination parent and child retain their link.
  5. For an incompatible move combined with a valid title edit, check that the saved title remains and the move error is still reported.

MR acceptance checklist

  • The incompatible-conversion regression fails on unpatched code and passes with the fix.
  • Permission checks and destination-type resolution still precede hierarchy validation and move mutations.
  • Validation failure results and unexpected database exceptions retain their existing semantics.
  • No broad exception rescue, full-model preflight validation, SQL-limit adjustment, migration, dependency change, or public API schema change is included.
  • Changelog: fixed is present on the first commit.
Local validation and known limitations

Validated candidate: 4da61f3f540d06823219b0f4abdfdcc42d61418f, based on d208d53dba0e8b3f019b96a5de64a17a7bac9fbe.

  • Full affected service, Notes, GraphQL, clone, bulk-move, and hierarchy files, plus compatibility diagnostics: 767 examples, 0 failures, 1 existing pending.
  • Related model and REST move examples: 38 examples, 0 failures, 1 existing pending.
  • FOSS affected files and compatibility diagnostics: 449 examples, 0 failures.
  • RuboCop: all 13 changed Ruby/spec files inspected, no offenses.
  • The two new overlapping-validation-error regressions fail before the correction and pass afterward.

The unchanged EE synced-epic fixture has three frozen-record setup failures also reproduced on the unmodified base. With a separate one-line fixture correction, the full affected EE WorkItems update file passes 55 examples. That fixture correction is not included in this MR.

A separate local GraphQL diagnostic for a compatible Incident move with a Task child exceeds the existing test-only SQL200 guard on both the unmodified base and this candidate. The hierarchy preflight records three queries for a type-changing move and none for an unchanged persisted type. The final error-replay correction adds no queries in those probes. These results are not a claim of a production SQL-limit exception, and no independent performance fix is included.

Counts from these runs overlap and must not be summed. The full repository suite and production-scale database performance were not validated. CI results must be checked against the newly pushed SHA rather than the previous successful pipeline.

AI assistance

AI tooling assisted with investigation, implementation, and local validation. The contributor is responsible for the submitted changes.

Edited by Whale Tech

Merge request reports

Loading
Loading