Skip to content

Removing then re-adding an issue to a cycle throws a unique-violation 500 #334

Description

@cavidelizade

Summary

Removing an issue from a cycle and then adding it back throws a 500 and the issue can never be re-added to that cycle.

Where

CycleIssue has a gorm.DeletedAt so RemoveCycleIssue (apps/api/internal/store/cycle.go) is a soft delete, but cycle_issues has a plain UNIQUE (cycle_id, issue_id) that ignores deleted_at (migration 000001). AddCycleIssue does a plain Create.

Repro

  1. Add issue X to cycle C.
  2. Remove X from C (row is soft-deleted, physical row survives).
  3. Add X to C again. The INSERT collides with the surviving row, Postgres returns a unique violation, the request 500s.

X can now never be re-added to C. The same failure hits CompleteCycle's transfer of incomplete issues when the target cycle previously held that issue.

Note

The codebase already handles this correctly elsewhere. PageStore.MoveTreeToProject hard-deletes project_pages for exactly this reason, and the workspace/project member upserts revive with Unscoped(). Cycle issues were missed. Every other join table (issue_assignees, issue_labels, module_issues, etc.) has no DeletedAt and hard-deletes, so they're fine.

Fix

Hard-delete cycle links, or upsert-revive the soft-deleted row, or make the constraint partial (WHERE deleted_at IS NULL).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions