Fixing intermittent error experienced with union types#298
Merged
rockwotj merged 3 commits intolinkedin:masterfrom Oct 22, 2025
Merged
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 <patrick.assuied@elationhealth.com>
passuied
commented
Oct 22, 2025
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 |
Contributor
Author
There was a problem hiding this comment.
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 <patrick.assuied@elationhealth.com>
da1388e to
46a0328
Compare
Contributor
Author
|
@mihaitodor and @rockwotj this issue is blocking us. Any way escalate review and approval? |
Signed-off-by: Patrick Assuied <patrick.assuied@elationhealth.com>
3 tasks
rockwotj
approved these changes
Oct 22, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 patrick.assuied@elationhealth.com