[Fix] Fix NaN position in notes resulting in not being able to create notes (#16818)
Following [discord thread](https://discord.com/channels/1130383047699738754/1453910755387899996/1453910755387899996), reproductible on twenty-eng https://github.com/user-attachments/assets/ae7f363d-87e1-44fa-8fe2-ee78412d62a7 Records positions are computed at record creation, depending on the position arg from the request, being equal to `last`, `first`, or not present. When being equal to last, as it is done when creating a note from the product, the position is calculated using `.maximum()` function which uses postgres' MAX function. If there is a `NaN` value among the list, the MAX will return `NaN` too. So if for some reason there is a NaN somewhere in the position column, all subsequent records being created with last position argument will be created with NaN value. Until [this PR](https://github.com/twentyhq/twenty/pull/16630), where we introduced a validation on position at record creation which throws when NaN is trying to be introduced as a position, this was going silent. (fyi @etiennejouan , not on you at all but for info) Looking into twenty-eng workspace, I found note records with NaN position dating back to august 2025, making it hard to understand and debug why they were introduced with NaN position. So I did not find the real root cause, but I suggest to - update record-position.service to fix the issue for subsequent records that go through this service (which is what is currently broken) - run a command to fix the existing records with NaN position for Notes, as it is where the issue happened for both the user reporting the issue on discord, and us on twenty-eng. So hopefully the problem was limited to Notes
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
export const sanitizeNumber = (value: number | null): number | null => {
|
||||
if (!isDefined(value) || Number.isNaN(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
Reference in New Issue
Block a user