-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] Nullable fields must have default values #7522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This pull request adds a validation check to ensure non-nullable fields have default values in the FieldMetadataService class.
- Added validation in
validateFieldMetadataInput
method to require default values for non-nullable fields - The change improves data integrity but may have implications for existing fields and data
- Consider adding a migration strategy for existing non-nullable fields without default values
- Evaluate the impact on API consumers and client-side applications that may need to adapt to this new requirement
- Review error handling and messaging to provide clear guidance for users encountering this validation
1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings
if (!fieldMetadataInput.isNullable) { | ||
if (!fieldMetadataInput.defaultValue) { | ||
throw new FieldMetadataException( | ||
'Default value is required for nullable fields', | ||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The condition and error message are inconsistent. It checks for non-nullable fields but the error message mentions nullable fields. This needs to be corrected.
if (!fieldMetadataInput.isNullable) { | ||
if (!fieldMetadataInput.defaultValue) { | ||
throw new FieldMetadataException( | ||
'Default value is required for nullable fields', | ||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This validation might be too strict. Some field types might not require a default value even if they're non-nullable (e.g., auto-incrementing IDs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix LGTM
- Fixing seeds after introducing the requirement for non-nullable fields to have a default value (#7522). - Empty string needs to be considered a valid default value
In [this](#7522) and [this](#7543) PR we introduced the impossibility to save a field that would be non nullable but without a default value. The check is actually called on the input while the defaultValue is added by the service on a "built" fieldMetadata to create or save. So far all fields created from the app it currently fails as both isNullable and defaultValue are undefined so falsy at that stage.
- Fixing seeds after introducing the requirement for non-nullable fields to have a default value (twentyhq#7522). - Empty string needs to be considered a valid default value
In [this](twentyhq#7522) and [this](twentyhq#7543) PR we introduced the impossibility to save a field that would be non nullable but without a default value. The check is actually called on the input while the defaultValue is added by the service on a "built" fieldMetadata to create or save. So far all fields created from the app it currently fails as both isNullable and defaultValue are undefined so falsy at that stage.
No description provided.