https://sonarly.com/issue/4058?type=bug Creating view fields fails with BUILDER_INTERNAL_SERVER_ERROR when a related entity (fieldMetadata, view, or viewFieldGroup) exists in the first workspace cache read but is absent from the second, separate cache read used during migration building. Fix: ## Root Cause A TOCTOU race condition between two separate workspace cache reads in `ViewFieldService.createMany`: - **Read #1** (lines 79–89 of `view-field.service.ts`): fetches `flatFieldMetadataMaps`, `flatViewMaps`, and `flatViewFieldGroupMaps` to resolve raw IDs (e.g. `fieldMetadataId`) into universal identifiers for building `flatViewFieldsToCreate`. - **Read #2** (inside `computeAllRelatedFlatEntityMaps` in `workspace-migration-validate-build-and-run-service.ts`): fetches all related entity maps used by the migration builder. If a concurrent metadata operation (field deletion, cache invalidation) occurs between Read #1 and Read #2, the referenced entity (e.g. `fieldMetadata` resolved in Read #1) may be absent from the second snapshot. When the migration builder then calls `findFlatEntityByUniversalIdentifierOrThrow` on the Read #2 snapshot, it throws `FlatEntityMapsException → BUILDER_INTERNAL_SERVER_ERROR`. ## Fix Pass the maps fetched in Read #1 as `preloadedFlatEntityMaps` to `validateBuildAndRunWorkspaceMigration`. Inside `computeAllRelatedFlatEntityMaps`, the pre-loaded maps are overlaid over the cache-fetched maps after Read #2: ```typescript file=packages/twenty-server/src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service.ts lines=210-219 const { flatApplicationMaps, ...cachedFlatEntityMaps } = await this.workspaceCacheService.getOrRecompute(workspaceId, [...]); const allRelatedFlatEntityMaps = isDefined(preloadedFlatEntityMaps) ? { ...cachedFlatEntityMaps, ...preloadedFlatEntityMaps } : cachedFlatEntityMaps; ``` This guarantees the entities resolved during ID-to-universal-identifier translation are present in the maps used for migration building — even if the cache is invalidated between the two async operations. Keys not covered by `preloadedFlatEntityMaps` (e.g. `featureFlagsMap`, `flatObjectMetadataMaps`) still come from the cache normally. The call site in `view-field.service.ts` now passes: ```typescript file=packages/twenty-server/src/engine/metadata-modules/view-field/services/view-field.service.ts lines=116-120 preloadedFlatEntityMaps: { flatFieldMetadataMaps, flatViewMaps, flatViewFieldGroupMaps, }, ```
The #1 Open-Source CRM
🌐 Website · 📚 Documentation · Roadmap ·
Discord ·
Figma
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
- Customize your objects and fields
- Create and manage permissions with custom roles
- Automate workflow with triggers and actions
- Emails, calendar events, files, and more
Personalize layouts with filters, sort, group by, kanban and table views
Customize your objects and fields
Create and manage permissions with custom roles
Automate workflow with triggers and actions
Emails, calendar events, files, and more
Stack
- TypeScript
- Nx
- NestJS, with BullMQ, PostgreSQL, Redis
- React, with Jotai, Emotion and Lingui
Thanks
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
- Star the repo
- Subscribe to releases (watch -> custom -> releases)
- Follow us on Twitter or LinkedIn
- Join our Discord
- Improve translations on Crowdin
- Contributions are, of course, most welcome!




