Skip to content
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

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

ijreilly
Copy link
Collaborator

@ijreilly ijreilly commented Oct 9, 2024

No description provided.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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

Comment on lines 748 to 755
if (!fieldMetadataInput.isNullable) {
if (!fieldMetadataInput.defaultValue) {
throw new FieldMetadataException(
'Default value is required for nullable fields',
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
);
}
}
Copy link
Contributor

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.

Comment on lines 748 to 755
if (!fieldMetadataInput.isNullable) {
if (!fieldMetadataInput.defaultValue) {
throw new FieldMetadataException(
'Default value is required for nullable fields',
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
);
}
}
Copy link
Contributor

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).

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix LGTM

@ijreilly ijreilly merged commit 7987221 into main Oct 9, 2024
7 of 8 checks passed
@ijreilly ijreilly deleted the fix-non-nullable-field-without-default-value branch October 9, 2024 12:02
@ijreilly ijreilly mentioned this pull request Oct 9, 2024
charlesBochet pushed a commit that referenced this pull request Oct 9, 2024
- 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
@ijreilly ijreilly mentioned this pull request Oct 10, 2024
ijreilly added a commit that referenced this pull request Oct 10, 2024
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.
harshit078 pushed a commit to harshit078/twenty that referenced this pull request Oct 14, 2024
harshit078 pushed a commit to harshit078/twenty that referenced this pull request Oct 14, 2024
- 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
harshit078 pushed a commit to harshit078/twenty that referenced this pull request Oct 14, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants