Conversation
| zero1 := v1Field.IsZero() | ||
| zero2 := v2Field.IsZero() | ||
|
|
||
| if zero1 || zero2 { |
There was a problem hiding this comment.
What about the other way around? Fields that are nil but are present in ForceSendFields should be set to their zero value.
There was a problem hiding this comment.
not sure what you mean, can you post an example testcase?
There was a problem hiding this comment.
consider:
a = foo{
myfield: nil,
ForceSendFields: []{"myfield"}
}
b = foo{
myfield: "",
ForceSendFields: []{"myfield"}
}
a and b should be equal in this case, regardless of the omitempty annotation.
There was a problem hiding this comment.
what type is myfield? it's not a string, right?
There was a problem hiding this comment.
In Go SDK ForceSendFields is only meaningful on "basic" types https://github.com/databricks/databricks-sdk-go/blob/main/marshal/types.go#L5
in cli repo libs/structs and libs/dyn we also apply on maps and slices. However, AFAIK it is never applied it to pointers.
|
Commit: 091ee38
26 interesting tests: 21 KNOWN, 2 flaky, 2 FAIL, 1 SKIP
Top 50 slowest tests (at least 2 minutes):
|
| return false | ||
| } | ||
|
|
||
| return equalValues(v1, v2) |
There was a problem hiding this comment.
Can't we just use reflect.DeepEqual here?
There was a problem hiding this comment.
no, see the comment about ForceSendFields
There was a problem hiding this comment.
This PR is prompted by a real issue btw where I did use reflect.DeepEqual but it did not do what's expected because ForceSendFields in one case was set but not in the other.
SDK always adds fields to ForceSendFields regardless of whether they are needed there or not. Our code in many places only adds it if the value is zero.
|
Commit: 2f558af
65 interesting tests: 23 MISS, 21 KNOWN, 16 FAIL, 3 flaky, 1 PANIC, 1 SKIP
Top 50 slowest tests (at least 2 minutes):
|
Changes
New function structdiff.IsEqual() which follows the same logic as structdiff.GetStructDiff() but does not build a diff.
Why
Need this in #4201
reflect.DeepEqual() does not work for types with ForceSendFields because ForceSendFields can have more or less fields in it without changing the actual value.
Tests
Unit tests.