Fixed plain object in field value for workflow#17470
Conversation
Greptile OverviewGreptile SummaryThis PR fixes a bug in Changes:
Context: Minor issue:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant WEM as WorkspaceEntityManager
participant ORC as objectRecordChangedValues
participant FMT as formatResult
participant WF as Workflow Event
WEM->>ORC: compare before/after records
ORC->>ORC: detect changed DATE_TIME field
ORC-->>WEM: return {fieldName: {before: null, after: '2026-01-27T10:59:15.525Z'}}
WEM->>FMT: format event diff data
Note over FMT: PR #17407 added strict<br/>DATE_TIME validation
FMT->>FMT: check if DATE_TIME field
FMT->>FMT: isPlainObject? (NEW)
Note over FMT: This PR adds support<br/>for plain objects
FMT-->>WEM: pass through plain object
WEM->>WF: emit workflow event with diff
|
| // @ts-expect-error legacy noImplicitAny | ||
| newData[dateTimeField.name] = dateIsoString; | ||
| } else if (isPlainObject(rawUpdatedDateTime)) { | ||
| const plainObjectValue = rawUpdatedDateTime; |
There was a problem hiding this comment.
unnecessary intermediate variable, can assign rawUpdatedDateTime directly
| const plainObjectValue = rawUpdatedDateTime; | |
| newData[dateTimeField.name] = rawUpdatedDateTime; |
Context Used: Context from dashboard - Avoid using inline returns in the codebase for better readability and maintainability. (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/twenty-server/src/engine/twenty-orm/utils/format-result.util.ts
Line: 213:213
Comment:
unnecessary intermediate variable, can assign `rawUpdatedDateTime` directly
```suggestion
newData[dateTimeField.name] = rawUpdatedDateTime;
```
**Context Used:** Context from `dashboard` - Avoid using inline returns in the codebase for better readability and maintainability. ([source](https://app.greptile.com/review/custom-context?memory=ecab015d-82e3-4483-9a36-3ed0a14495bf))
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Pull request overview
This PR adjusts the formatResult DATE_TIME handling to support workflow use cases where DATE_TIME fields are represented as plain objects (e.g. { before, after }), avoiding spurious errors introduced by the previous refactor.
Changes:
- Extends the inferred type of
rawUpdatedDateTimewithinformatResultto includeRecord<string, unknown>. - Adds an
isPlainObjectbranch so plain-object DATE_TIME values are passed through without conversion instead of triggering an error. - Updates the DATE_TIME validation error message to include
JSON.stringifyoutput and mention plain-object support.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else { | ||
| throw new Error( | ||
| `Invalid DATE_TIME field "${dateTimeField.name}", value: "${rawUpdatedDateTime}", it should be a string or Date instance, (current type : ${typeof rawUpdatedDateTime}).`, | ||
| `Invalid DATE_TIME field "${dateTimeField.name}", value: "${JSON.stringify(rawUpdatedDateTime)}", it should be a string, Date instance or plain object, (current type : ${typeof rawUpdatedDateTime}).`, | ||
| ); |
There was a problem hiding this comment.
Using JSON.stringify(rawUpdatedDateTime) inside the error message can itself throw (e.g., for values containing BigInt or circular references), which would mask the intended, more descriptive Error and surface a generic TypeError instead. It would be safer to stringify defensively (e.g., via a helper that catches JSON.stringify failures and falls back to String(value)), so that the error path is robust even when the value is of an unexpected type.
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:28451 This environment will automatically shut down when the PR is closed or after 5 hours. |
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/twenty-shared/src/utils/strings/stringifySafely.ts">
<violation number="1" location="packages/twenty-shared/src/utils/strings/stringifySafely.ts:15">
P2: `JSON.stringify` returns `undefined` for unsupported top-level values (e.g., functions or symbols), so this line can return `undefined` despite the function promising a string. Capture the result and fall back to `String(value)` when JSON serialization yields `undefined`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
1 similar comment
|
Hey @lucasbordeau! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
This PR fixes a bug that arises in
formatResultfollowing up the recent refactor for DATE_TIME : #17407In the case of workflows, we pass a plain object to
formatResult:So a case has been added to handle this.
@Weiko are we ok with this more restrictive else-if part in this util ? We could also just put a
continuefor unknown shapes.