Skip to content

fix(issues): return 422 validation error for non-existent parentId or goalId (#7656) - #11087

Open
wakqasahmed wants to merge 2 commits into
paperclipai:masterfrom
wakqasahmed:fix/issue-fk-validation-7656
Open

fix(issues): return 422 validation error for non-existent parentId or goalId (#7656)#11087
wakqasahmed wants to merge 2 commits into
paperclipai:masterfrom
wakqasahmed:fix/issue-fk-validation-7656

Conversation

@wakqasahmed

Copy link
Copy Markdown

Fixes #7656

Summary

When updating or creating an issue with a non-existent parentId or goalId, Drizzle/Postgres threw a foreign-key constraint violation (issues_parent_id_issues_id_fk / issues_goal_id_goals_id_fk), resulting in an unhandled HTTP 500 error with a raw stack trace. Agent clients observing a 500 would treat it as a transient error and repeatedly retry the invalid request.

Solution

  1. Added validation checks assertParentIssueExists and assertGoalExists to issueService in server/src/services/issues.ts before creating or updating an issue.
  2. Added parseForeignKeyError helper to catch database foreign-key violations and map them to clean 422 HttpError validation responses ("Parent issue not found" / "Goal not found").
  3. Updated PATCH /api/issues/:id and issue creation routes to return 422 Unprocessable Entity instead of 500 on foreign key violations.
  4. Added test coverage in server/src/__tests__/issues-fk-validation.test.ts.

@commitperclip

commitperclip Bot commented Aug 8, 2026

Copy link
Copy Markdown

Hey @wakqasahmed! Before this PR can be reviewed, a few things need attention:

Missing or incomplete:

  • Missing section: ## Thinking Path
  • Missing section: ## What Changed
  • Missing section: ## Verification
  • Missing section: ## Risks
  • Missing section: ## Model Used
  • Add the dedup-search checkbox to your PR description and check it once you have searched the GitHub PR list for similar PRs. See the PR template at .github/PULL_REQUEST_TEMPLATE.md and CONTRIBUTING.md → "Before You Start: Search First".

Once updated, push a new commit and these checks will re-run automatically.

— commitperclip

…K-validation refactor

The try/catch wrap added around issueService.create()'s transaction (for
TOCTOU-safe FK error translation) accidentally dropped the rest of the
function body: workspace/project resolution, issue-number allocation,
insert, watchdog/label/blocked-by wiring, and the return statement were
all deleted, and the create() method's closing brace and catch block
were missing entirely. This left an unterminated `.select({` merged
directly into the JSDoc comment for importIssues(), corrupting the file.

Restored the full original function body (unchanged) inside the
try block, added the missing catch block that mirrors update()'s
parseForeignKeyError handling, and closed out the method properly.

Verified server/src/__tests__/issues-fk-validation.test.ts (10/10),
issues-parent-id-alias.test.ts, and issues-goal-context-routes.test.ts
(22/22 total) pass, confirming issues.ts now parses/imports correctly
and the FK-validation behavior for both create and update paths works
as intended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PATCH /api/issues/:id with a non-existent parentId (or goalId) returns 500 (raw Postgres FK error) instead of 400/422

1 participant