-
Notifications
You must be signed in to change notification settings - Fork 229
Fixing intermittent error experienced with union types #298
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
Fixing intermittent error experienced with union types #298
Conversation
…12 where calling NativeFromBinary() then TextFromNative() on union types would sometime throw error such as:
```
Error: cannot encode textual map: value for \"policy_id\" does not match its schema: cannot encode textual union: cannot encode textual null: expected: Go nil; received: int64
```
Even though `policy_id` is defined as
```
{
"default": null,
"name": "policy_id",
"type": [
"null",
"long"
]
},
```
and encoded value is `140866783150163`
or also
```Error: cannot encode textual map: value for \"plans\" does not match its schema: cannot encode textual union: cannot encode textual array item 1; map[carrier_id:map[null:63919423854] hippospace:ellie_insurance-api-dev-feature-clone-car id:map[null:63919489391] name:Kaiser Senior practice_id:655364]: cannot encode textual map: value for \"carrier_id\" does not match its schema: cannot encode textual union: cannot encode textual null: expected: Go nil; received: int64.
```
- Refactored sorting of allowed types in nativeAvroFromTextualJSON to avoid mutating shared state. Create a local copy for sorting to ensure thread safety and maintain integrity of codecInfo.
Signed-off-by: Patrick Assuied <[email protected]>
union.go
Outdated
| // double, float, int, long | ||
| // that makes the priorities right by chance | ||
| sort.Strings(cr.allowedTypes) | ||
| // Sort a local copy to avoid mutating cr.allowedTypes shared state |
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 found that union handling was mutating shared cr.allowedTypes and checkAll iterated over it instead of its parameter, which could cause wrong branch labels like "null" instead of "long".
As a result:
- Use the allowedTypes parameter inside checkAll.
- Stop sorting cr.allowedTypes and instead create a local copy to use inside checkAll
…t it's fixed Signed-off-by: Patrick Assuied <[email protected]>
da1388e to
46a0328
Compare
|
@mihaitodor and @rockwotj this issue is blocking us. Any way escalate review and approval? |
Signed-off-by: Patrick Assuied <[email protected]>
Fixes issue
#299
Description
Fixing intermittent error experienced with union types
Even though
policy_idis defined asand encoded value is
140866783150163or also
Signed-off-by: Patrick Assuied [email protected]