Files
twenty/packages/twenty-front
Sonarly Claude Code eadfa26b70 fix: gracefully skip orphaned relation targets in useRelatedRecordCommands
https://sonarly.com/issue/18537?type=bug

The `useRelatedRecordCommands` hook throws an unhandled error when a relation field on an object (e.g., `people`) references a target custom object that no longer exists in the metadata store, crashing the page.

Fix: Two files changed to gracefully handle orphaned relation targets (relation fields that reference deleted/missing custom objects):

1. **`useRelatedRecordCommands.ts`** (line 60-64): Replaced `throw new Error(...)` with `continue`. When iterating ONE_TO_MANY relation fields to build command menu items, if the target object metadata is not found, the loop now skips that field instead of crashing the React render tree. This is the correct behavior — there's no command menu item to create for a non-existent object.

2. **`generateDepthRecordGqlFieldsFromFields.ts`** (line 57-61): Replaced `throw new Error(...)` with `return recordGqlFields` (the accumulator). Inside the `reduce`, when a relation field references a target object that doesn't exist in the metadata, we skip it and return the fields accumulated so far. This prevents the GraphQL field generation from crashing when building queries for objects with orphaned relations.

Both cases are data consistency edge cases — not programming invariants. When a custom object is deleted, relation fields on other objects may temporarily still reference it (due to localStorage cache staleness or incomplete server-side cleanup). Crashing the entire page is disproportionate; skipping the orphaned field is the correct degraded behavior.
2026-03-25 23:32:37 +00:00
..
2026-02-17 11:24:33 +01:00

Run yarn dev while server running on port 3000