Sonarly Claude Code 8487ae3fd3 Cache miss when attaching record in one-to-many relation picker on custom objects
https://sonarly.com/issue/4153?type=bug

When a user selects a record in the multi-select relation picker for a one-to-many field, the code attempts to read the target record from Apollo cache but fails because the record was fetched via search API and hasn't been fully cached yet.

Fix: Replaced the hard `throw new Error('Could not find cached related record')` with a graceful `isDefined(cachedTargetRecord)` guard in `useRecordOneToManyFieldAttachTargetRecord.ts`.

**What changed:** When `getRecordFromCache()` returns `null` (because the target record hasn't been hydrated into Apollo cache yet — common when records are found via search API), the code now skips the optimistic cache update and proceeds directly to the `updateOneRecord` API call. Previously it threw, which crashed the entire attach flow.

**Why this is correct:** The cache update block (lines 62-98) is an optimistic UI optimization that updates the local Apollo cache to reflect the previous relation being cleared. It is not required for correctness — the `updateOneRecord` mutation (line 100) is what actually persists the relation change on the server. When the mutation response returns, Apollo will update the cache anyway.

Also cleaned up the blank line in imports that was left by the original code.

Note: Two unmerged branches already contain essentially identical fixes (`311ac35ddf` by neo773, `467621ba21` by Thomas Trompette), confirming this is a known issue with a consensus fix approach.
2026-03-11 16:33:26 +00:00
2025-08-07 17:02:12 +02:00
2025-07-08 15:13:02 +02:00
2026-03-04 00:50:06 +01:00
2026-03-11 16:30:28 +01:00
2026-03-04 00:50:06 +01:00

Twenty logo

The #1 Open-Source CRM

🌐 Website · 📚 Documentation · Roadmap · Discord · Figma


Cover


Installation

See: 🚀 Self-hosting 🖥️ Local Setup

Why Twenty

We built Twenty for three reasons:

CRMs are too expensive, and users are trapped. Companies use locked-in customer data to hike prices. It shouldn't be that way.

A fresh start is required to build a better experience. We can learn from past mistakes and craft a cohesive experience inspired by new UX patterns from tools like Notion, Airtable or Linear.

We believe in Open-source and community. Hundreds of developers are already building Twenty together. Once we have plugin capabilities, a whole ecosystem will grow around it.


What You Can Do With Twenty

Please feel free to flag any specific needs you have by creating an issue.

Below are a few features we have implemented to date:

Personalize layouts with filters, sort, group by, kanban and table views

Companies Kanban Views

Customize your objects and fields

Setting Custom Objects

Create and manage permissions with custom roles

Permissions

Automate workflow with triggers and actions

Workflows

Emails, calendar events, files, and more

Other Features


Stack

Thanks

Chromatic Greptile Sentry Crowdin E2B

Thanks to these amazing services that we use and recommend for UI testing (Chromatic), code review (Greptile), catching bugs (Sentry) and translating (Crowdin).

Join the Community

Languages
TypeScript 78%
MDX 18.5%
JavaScript 3.1%
Python 0.2%