-
Notifications
You must be signed in to change notification settings - Fork 44
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: Make all array kinds nillable #2534
fix: Make all array kinds nillable #2534
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.
Thanks for finding this :) Got a couple of todos for you though
client/schema_field_description.go
Outdated
@@ -154,7 +154,11 @@ func (k ScalarArrayKind) Underlying() string { | |||
} | |||
|
|||
func (k ScalarArrayKind) IsNillable() bool { | |||
return k == FieldKind_NILLABLE_BOOL_ARRAY || | |||
return k == FieldKind_BOOL_ARRAY || |
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.
todo: This could be simplified to return true
.
@@ -154,7 +154,11 @@ func (k ScalarArrayKind) Underlying() string { | |||
} | |||
|
|||
func (k ScalarArrayKind) IsNillable() bool { |
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.
todo: Please add some integration tests that fail before the production code is fixed.
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.
I'm actually not sure how the tests did not fail before. I'm still investigating, but I believe its because of encoding / decoding of []int{}
vs nil
.
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.
I've added a unit test, but I don't think an integration test can actually catch this problem due to the encoding I mentioned above.
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.
I believe its because of encoding / decoding of []int{} vs nil.
I think that might be another bug, client.validateFieldSchema
does not appear to reject nil values for non-nillable fields. I'll create a new ticket, is kind of out of scope here if that is what was hiding this PR's bug.
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.
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.
LGTM, thanks Keenan :)
// This test documents a bug where array values | ||
// were not returning the correct value for IsNillable | ||
// and were also not convertible to a normal nil kind. | ||
func TestArrayValue_IsNillable(t *testing.T) { |
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.
thought: I'm not sure that this is correct. Please wait before merging.
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.
All good here. I got mixed up because of us not updating the field kinds.
client/normal_nil.go
Outdated
@@ -34,13 +34,13 @@ func NewNormalNil(kind FieldKind) (NormalValue, error) { | |||
return NewNormalNillableString(immutable.None[string]()), nil | |||
case FieldKind_NILLABLE_BLOB: | |||
return NewNormalNillableBytes(immutable.None[[]byte]()), nil | |||
case FieldKind_NILLABLE_BOOL_ARRAY: | |||
case FieldKind_BOOL_ARRAY, FieldKind_NILLABLE_BOOL_ARRAY: |
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.
todo: This should be changed to
case FieldKind_BOOL_ARRAY:
return NewNormalIntNillableArray(immutable.None[[]bool]()), nil
case FieldKind_NILLABLE_BOOL_ARRAY:
return NewNormalNillableBoolNillableArray(immutable.None[[]immutable.Option[bool]]()), nil
and similarly for the other array types.
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.
Nice spot :)
FieldKind_NILLABLE_BOOL_ARRAY, | ||
FieldKind_NILLABLE_INT_ARRAY, | ||
FieldKind_NILLABLE_FLOAT_ARRAY, | ||
FieldKind_NILLABLE_STRING_ARRAY, |
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.
todo: sorry, but I'm trying to figure out what this PR actually tries to achieve.
Looking at this test I'm a bit confused.
We have the following array types:
- FieldKind__ARRAY - NOT nillable array with NOT nillable elements
- FieldKind_NILLABLE__ARRAY - NOT nillable array with nillable elements
- FieldKind__NILLABLE_ARRAY - nillable array with NOT nillable elements
- FieldKind_NILLABLE__NILLABLE_ARRAY - nillable array with nillable elements
At least this is how these different array kinds are supposed to be distinguished.
At the moment IsNillable
on ScalarArrayKind
return true IIRC only elements are nillable, but it's no ideal. I also planned to put some effort on this.
So please clarify which of those 4 types you are changing and how.
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.
There was a discord conversation around this, all the scalar arrays are nillable atm, the enum values are just stuck with the old names. e.g. FieldKind_INT_ARRAY
is nillable, with non-nillable elements.
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.
At the moment, FieldKind__ARRAY
is a Nillable array with NOT nillable elements. That is where we all get confused. This needs to be fix. This PR ensures that things work as they should given the current naming.
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.
FieldKind__NILLABLE_ARRAY
and FieldKind_NILLABLE__NILLABLE_ARRAY
don't exist at the moment.
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.
looks like I missed this discord conversation. All right then
Relevant issue(s)
Resolves #2533
Description
This PR fixes a bug where
ScalarArrayKind.IsNillable()
returned an incorrect value for arrays of non-nillable values.Tasks
How has this been tested?
make test
Specify the platform(s) on which this was tested: