-
Notifications
You must be signed in to change notification settings - Fork 299
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: unmarshal numeric fields regardless of them being int or float #251
Conversation
This does not work for me for the I think the problem is here: Lines 141 to 148 in f5f7cf5
Because |
test_data/find_track.txt
Outdated
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.
Could we duplicate the test data, rather than modifying the existing tests, to ensure we have a mixture of cases with floats and with integers, it looks like Spotify can't make their mind up and it'd be good to know we can handle both!
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.
done
spotify.go
Outdated
return err | ||
} | ||
|
||
i.Height = int(v.Height) |
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 wonder if longterm it makes sense for us to return these fields as floats rather than casting them back to ints. It'd be a breaking change though so perhaps worth bundling with some other fixes. I'm also a little curious if it'd make more sense to have a custom type to avoid all these unmarshallers which could be easily forgotten.
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 kept it int for now, but removed the unmarshallers in favour of a custom type (more below)
Thanks for raising this - could you address my remark re: the test data ? I think it's important to prove we can handle both ints and floats. Then I'm happy to move forward with this. |
@strideynet, I rewrote it with the custom type to avoid multiple unmarshallers. It's much simpler and flexible now. That said, it introduces a breaking change for comparisons. So if you, for some reason, compare one of the fields (e.g. the follower count) to an integer variable, it will break, as the custom type is not comparable to the int. playlist.Followers > 100 // still works
threshold := 100
playlist.Followers > threshold // doesn't work (mismatched types Numeric and int) I still think this is a better solution than chaining the unmarshallers on top of each other, but since this is a bc-break, we/you could consider switching to floats (which would actually be a small change now that there's a custom type). Thanks EDIT: it's a bc-break invoked by a bc-break by Spotify, so maybe not a big deal (bc-break vs. doesn't work). |
Thanks - I think I'm happy enough with this hack for now. I'll cut a release with a breaking change warning. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/zmb3/spotify/v2](https://togithub.com/zmb3/spotify) | `v2.4.1` -> `v2.4.2` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fzmb3%2fspotify%2fv2/v2.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fzmb3%2fspotify%2fv2/v2.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fzmb3%2fspotify%2fv2/v2.4.1/v2.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fzmb3%2fspotify%2fv2/v2.4.1/v2.4.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>zmb3/spotify (github.com/zmb3/spotify/v2)</summary> ### [`v2.4.2`](https://togithub.com/zmb3/spotify/releases/tag/v2.4.2) [Compare Source](https://togithub.com/zmb3/spotify/compare/v2.4.1...v2.4.2) #### What's Changed - Update the link to information on rate limits by [@​oifj34f34f](https://togithub.com/oifj34f34f) in [https://github.com/zmb3/spotify/pull/245](https://togithub.com/zmb3/spotify/pull/245) - Enable race detection in CI testing by [@​strideynet](https://togithub.com/strideynet) in [https://github.com/zmb3/spotify/pull/252](https://togithub.com/zmb3/spotify/pull/252) - Update CI test steps by [@​strideynet](https://togithub.com/strideynet) in [https://github.com/zmb3/spotify/pull/253](https://togithub.com/zmb3/spotify/pull/253) - Update Lint CI action by [@​strideynet](https://togithub.com/strideynet) in [https://github.com/zmb3/spotify/pull/254](https://togithub.com/zmb3/spotify/pull/254) - build(deps): bump google.golang.org/protobuf from 1.27.1 to 1.33.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/zmb3/spotify/pull/255](https://togithub.com/zmb3/spotify/pull/255) - fix: unmarshal numeric fields regardless of them being int or float by [@​wernerdweight](https://togithub.com/wernerdweight) in [https://github.com/zmb3/spotify/pull/251](https://togithub.com/zmb3/spotify/pull/251) - build(deps): bump golang.org/x/net from 0.17.0 to 0.23.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/zmb3/spotify/pull/259](https://togithub.com/zmb3/spotify/pull/259) #### New Contributors - [@​oifj34f34f](https://togithub.com/oifj34f34f) made their first contribution in [https://github.com/zmb3/spotify/pull/245](https://togithub.com/zmb3/spotify/pull/245) - [@​wernerdweight](https://togithub.com/wernerdweight) made their first contribution in [https://github.com/zmb3/spotify/pull/251](https://togithub.com/zmb3/spotify/pull/251) **Full Changelog**: zmb3/spotify@v2.4.1...v2.4.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/jaredallard/miku). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMDEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjMwMS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This fixes #243. I also updated the test data so that it contains float values.