fix: allow identical singular and plural labels for objects (#18678)

## Summary

Closes #18673

Some languages (e.g., German "Unternehmen") and even English words
(sheep, deer, aircraft, series) have identical singular and plural
forms. Twenty previously blocked saving when labels matched, making it
impossible to correctly name objects in these cases.

- **Labels** are purely display strings — removed the equality
validation from both the frontend Zod schema and backend validator
- **API names** (nameSingular/namePlural) must stay different since they
generate distinct GraphQL resolvers (`findOne` vs `findMany`,
`createOne` vs `createMany`, etc.) and REST endpoints — this validation
is preserved
- Added a shared `computeMetadataNamesFromLabels` util in
`twenty-shared` that auto-appends `'s'` to the plural API name when both
labels produce the same camelCase name (e.g., "Unternehmen" →
`unternehmen` / `unternehmens`)
- Both the frontend form and backend sync-check use the same shared util
— single source of truth, no duplicated logic

**No retroactive impact**: since the old code prevented identical labels
from ever being saved, no existing workspace has `labelSingular ===
labelPlural`.

## Test plan

- [x] New unit tests for `computeMetadataNamesFromLabels` (7 tests:
standard labels, Sheep, Unternehmen, Aircraft, empty labels, different
labels, applyCustomSuffix)
- [x] Updated frontend schema validation tests (identical labels with
different names now passes; identical names still fails)
- [x] Updated backend integration test cases (removed identical-label
failing cases)
- [ ] Manual: create a new object with identical singular/plural labels
(e.g. "Sheep" / "Sheep") — should save successfully with API names
`sheep` / `sheeps`
- [ ] Manual: verify existing objects with different labels still work
unchanged


Made with [Cursor](https://cursor.com)
This commit is contained in:
Félix Malfait
2026-03-16 18:07:34 +01:00
committed by GitHub
parent 13ff7af297
commit c4e55d08ff
23 changed files with 204 additions and 1572 deletions
@@ -1 +0,0 @@
export const DATABASE_IDENTIFIER_MAXIMUM_LENGTH = 63;
@@ -1,3 +1,3 @@
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength';
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'twenty-shared/metadata';
export const FIELD_NAME_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH;
export const FIELD_NAME_MAXIMUM_LENGTH = IDENTIFIER_MAX_CHAR_LENGTH;
@@ -1,3 +1,3 @@
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength';
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'twenty-shared/metadata';
export const OBJECT_NAME_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH;
export const OBJECT_NAME_MAXIMUM_LENGTH = IDENTIFIER_MAX_CHAR_LENGTH;
@@ -1,3 +1,3 @@
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength';
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'twenty-shared/metadata';
export const OPTION_VALUE_MAXIMUM_LENGTH = DATABASE_IDENTIFIER_MAXIMUM_LENGTH;
export const OPTION_VALUE_MAXIMUM_LENGTH = IDENTIFIER_MAX_CHAR_LENGTH;
@@ -8,7 +8,7 @@ import { fieldMetadataItemSchema } from '@/object-metadata/validation-schemas/fi
import { AdvancedSettingsContentWrapperWithDot } from '@/settings/components/AdvancedSettingsContentWrapperWithDot';
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
import { SettingsOptionCardContentToggle } from '@/settings/components/SettingsOptions/SettingsOptionCardContentToggle';
import { DATABASE_IDENTIFIER_MAXIMUM_LENGTH } from '@/settings/data-model/constants/DatabaseIdentifierMaximumLength';
import { IDENTIFIER_MAX_CHAR_LENGTH } from 'twenty-shared/metadata';
import { getErrorMessageFromError } from '@/settings/data-model/fields/forms/utils/errorMessages';
import { IconPicker } from '@/ui/input/components/IconPicker';
import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
@@ -202,7 +202,7 @@ export const SettingsDataModelFieldIconLabelForm = ({
readOnly={readonly}
disabled={!isNameEditEnabled}
fullWidth
maxLength={DATABASE_IDENTIFIER_MAXIMUM_LENGTH}
maxLength={IDENTIFIER_MAX_CHAR_LENGTH}
RightIcon={() =>
apiNameTooltipText && (
<>
@@ -25,7 +25,7 @@ import { Card } from 'twenty-ui/layout';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
import { type StringKeyOf } from 'type-fest';
import { useNavigateSettings } from '~/hooks/useNavigateSettings';
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/computeMetadataNameFromLabel';
import { computeMetadataNamesFromLabels } from '~/pages/settings/data-model/utils/computeMetadataNamesFromLabels';
type SettingsDataModelObjectAboutFormProps = {
disableEdition?: boolean;
@@ -146,25 +146,24 @@ export const SettingsDataModelObjectAboutForm = ({
shouldValidate: true,
});
if (isLabelSyncedWithName) {
fillNamePluralFromLabelPlural(labelPluralFromSingularLabel);
fillNamesFromLabels(labelSingular, labelPluralFromSingularLabel);
}
};
const fillNameSingularFromLabelSingular = (
labelSingular: string | undefined,
const fillNamesFromLabels = (
currentLabelSingular: string,
currentLabelPlural: string,
) => {
if (!isDefined(labelSingular)) return;
const { nameSingular, namePlural } = computeMetadataNamesFromLabels(
currentLabelSingular,
currentLabelPlural,
);
setValue('nameSingular', computeMetadataNameFromLabel(labelSingular), {
setValue('nameSingular', nameSingular, {
shouldDirty: true,
shouldValidate: true,
});
};
const fillNamePluralFromLabelPlural = (labelPlural: string | undefined) => {
if (!isDefined(labelPlural)) return;
setValue('namePlural', computeMetadataNameFromLabel(labelPlural), {
setValue('namePlural', namePlural, {
shouldDirty: true,
shouldValidate: true,
});
@@ -215,9 +214,6 @@ export const SettingsDataModelObjectAboutForm = ({
onChange={(value) => {
onChange(capitalize(value));
fillLabelPlural(capitalize(value));
if (isLabelSyncedWithName === true) {
fillNameSingularFromLabelSingular(value);
}
}}
onBlur={() => onNewDirtyField?.()}
disabled={disableEdition}
@@ -243,7 +239,7 @@ export const SettingsDataModelObjectAboutForm = ({
onChange={(value) => {
onChange(capitalize(value));
if (isLabelSyncedWithName === true) {
fillNamePluralFromLabelPlural(value);
fillNamesFromLabels(labelSingular, capitalize(value));
}
}}
onBlur={() => onNewDirtyField?.()}
@@ -411,8 +407,7 @@ export const SettingsDataModelObjectAboutForm = ({
value === true &&
(isCustomObject || isbeingCreatedObject)
) {
fillNamePluralFromLabelPlural(labelPlural);
fillNameSingularFromLabelSingular(labelSingular);
fillNamesFromLabels(labelSingular, labelPlural);
}
onNewDirtyField?.();
}}
@@ -34,20 +34,6 @@ exports[`settingsDataModelObjectAboutFormSchema fails when labels are empty stri
"labelPlural"
],
"message": "Too small: expected string to have >=1 characters"
},
{
"code": "custom",
"message": "Singular and plural labels must be different",
"path": [
"labelPlural"
]
},
{
"code": "custom",
"message": "Singular and plural labels must be different",
"path": [
"labelSingular"
]
}
]]
`;
@@ -92,20 +78,20 @@ exports[`settingsDataModelObjectAboutFormSchema fails when required fields are m
]]
`;
exports[`settingsDataModelObjectAboutFormSchema fails when singular and plural labels are the same 1`] = `
exports[`settingsDataModelObjectAboutFormSchema fails when singular and plural labels are the same and names are the same 1`] = `
[ZodError: [
{
"code": "custom",
"message": "Singular and plural labels must be different",
"message": "Singular and plural names must be different",
"path": [
"labelPlural"
"nameSingular"
]
},
{
"code": "custom",
"message": "Singular and plural labels must be different",
"message": "Singular and plural names must be different",
"path": [
"labelSingular"
"namePlural"
]
}
]]
@@ -50,6 +50,19 @@ describe('settingsDataModelObjectAboutFormSchema', () => {
expectedSuccess: true,
},
},
{
title: 'validates input with identical labels but different names',
context: {
input: {
...validInput,
labelSingular: 'Sheep',
labelPlural: 'Sheep',
nameSingular: 'sheep',
namePlural: 'sheeps',
},
expectedSuccess: true,
},
},
];
const failsValidationTestsUseCase: EachTestingContext<{
@@ -90,12 +103,15 @@ describe('settingsDataModelObjectAboutFormSchema', () => {
},
},
{
title: 'fails when singular and plural labels are the same',
title:
'fails when singular and plural labels are the same and names are the same',
context: {
input: {
...validInput,
labelPlural: 'Same Label',
labelSingular: 'Same Label',
namePlural: 'sameName',
nameSingular: 'sameName',
},
expectedSuccess: false,
},
@@ -30,23 +30,7 @@ const settingsDataModelFormFieldsSchema = z.object({
export const settingsDataModelObjectAboutFormSchema =
settingsDataModelFormFieldsSchema.superRefine(
({ labelPlural, labelSingular, namePlural, nameSingular }, ctx) => {
const labelsAreDifferent =
labelPlural.trim().toLowerCase() !== labelSingular.trim().toLowerCase();
if (!labelsAreDifferent) {
const labelFields: ReadonlyKeysArray<ObjectMetadataItem> = [
'labelPlural',
'labelSingular',
];
labelFields.forEach((field) =>
ctx.addIssue({
code: 'custom',
message: t`Singular and plural labels must be different`,
path: [field],
}),
);
}
({ namePlural, nameSingular }, ctx) => {
const nameAreDifferent =
nameSingular.toLowerCase() !== namePlural.toLowerCase();
if (!nameAreDifferent) {