fix(issues): return 422 validation error for non-existent parentId or goalId (#7656) - #11087
Open
wakqasahmed wants to merge 2 commits into
Open
fix(issues): return 422 validation error for non-existent parentId or goalId (#7656)#11087wakqasahmed wants to merge 2 commits into
wakqasahmed wants to merge 2 commits into
Conversation
|
Hey @wakqasahmed! Before this PR can be reviewed, a few things need attention: Missing or incomplete:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7656
Summary
When updating or creating an issue with a non-existent
parentIdorgoalId, 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
assertParentIssueExistsandassertGoalExiststoissueServiceinserver/src/services/issues.tsbefore creating or updating an issue.parseForeignKeyErrorhelper to catch database foreign-key violations and map them to clean 422HttpErrorvalidation responses ("Parent issue not found" / "Goal not found").PATCH /api/issues/:idand issue creation routes to return 422 Unprocessable Entity instead of 500 on foreign key violations.server/src/__tests__/issues-fk-validation.test.ts.