fix: removeuseMergeRecordRelatationship and simplify dry run response#15486
fix: removeuseMergeRecordRelatationship and simplify dry run response#15486etiennejouan merged 6 commits intotwentyhq:mainfrom
Conversation
There was a problem hiding this comment.
Greptile Overview
Greptile Summary
This PR attempts to simplify the merge preview logic by removing the useMergeRecordRelationships hook, with the assumption that the backend now returns fully populated relation data in the dry run response.
Critical Issue Identified:
- The backend's
fetchRecordsToMergemethod (incommon-merge-many-query-runner.service.ts) uses TypeORM'srepository.find()with only aselectparameter, which does not load relation objects - It only fetches scalar fields and foreign key IDs (e.g.,
companyId) but not the actual related records (e.g., company details) - The
processNestedRelationscall that populates relations is only executed for actual merges (line 119-123), not for dry runs which return early (line 78-85) - The deleted
useMergeRecordRelationshipshook was the only code fetching complete relation data for the preview
Impact:
- Merge preview will display incomplete relation information (only IDs, not the actual related record data like company name)
- This will cause the bug described in issue #15201 to persist or worsen
- Users won't see accurate preview data before confirming a merge
Required Fix:
Either the backend needs to be updated to populate relations in dry run responses (PR #15484 mentioned but not found/merged), or this frontend change should not be merged until the backend is ready.
Confidence Score: 0/5
- This PR will break the merge preview feature by removing critical relation data fetching logic without a proper backend replacement
- The removal of
useMergeRecordRelationshipseliminates the only code path that fetches complete relation objects for the merge preview. The backend's dry run response does not include populated relations - it only returns foreign key IDs. This is a critical regression that will cause merge previews to show incomplete data, directly impacting the user experience and potentially causing incorrect merge decisions - Both files require attention:
useMergePreview.tsneeds the relation fetching logic restored, anduseMergeRecordRelationships.tsshould not be deleted until backend properly handles relations in dry run
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| packages/twenty-front/src/modules/object-record/record-merge/hooks/useMergePreview.ts | 1/5 | Removed critical hook for fetching relation data, breaking merge preview with incomplete relation information |
| packages/twenty-front/src/modules/object-record/record-merge/hooks/useMergeRecordRelationships.ts | 0/5 | Deleted hook that was responsible for fetching and merging relation data into preview records |
Sequence Diagram
sequenceDiagram
participant UI as Merge Preview UI
participant Hook as useMergePreview
participant API as mergeManyRecords
participant Backend as CommonMergeManyQueryRunner
participant DB as Database
UI->>Hook: Select records to merge
Hook->>API: mergeManyRecords(preview: true)
API->>Backend: Mutation with dryRun: true
Backend->>DB: fetchRecordsToMerge (select only)
Note over Backend,DB: Only fetches scalar fields + foreign key IDs<br/>(e.g., companyId, NOT company object)
DB-->>Backend: Records with IDs only
Backend->>Backend: performDeepMerge
Backend->>Backend: createDryRunResponse
Note over Backend: processRecord transforms data<br/>but relations are NOT populated
Backend-->>API: Preview record (missing relation objects)
API->>Hook: upsertRecordsInStore
Note over Hook: REMOVED: useMergeRecordRelationships<br/>Previously fetched full relation data
Hook-->>UI: Display preview with incomplete relations
2 files reviewed, 1 comment
packages/twenty-front/src/modules/object-record/record-merge/hooks/useMergePreview.ts
Show resolved
Hide resolved
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:11279 This environment will automatically shut down when the PR is closed or after 5 hours. |
|
I realized the issue was in
Screen.Recording.2025-11-05.at.1.14.01.PM.mov |
etiennejouan
left a comment
There was a problem hiding this comment.
Hi @harshit078 its works well. Well done and thank you for your contribution !
|
Thanks @harshit078 for your contribution! |
|
Even though this PR fixes the initial issue Stephanie reported, the merge feature could benefit from some other improvements (not a priority):
@charlesBochet have you any hint to share ? |
|
|
I was worried that the fake record might interfere with other features. This fake record is related (relation) to other real records. If there's ever a fetch performed in the store based on these relationships, it would come up. Definitely unlikely? We could also say that we clean up this record when exiting the preview. |


Description
Visual Appearance
Screen.Recording.2025-10-31.at.1.15.29.PM.mov