rinukkusu / spotify-dart

A dart library for interfacing with the Spotify API.
BSD 3-Clause "New" or "Revised" License
206 stars 93 forks source link

Bug: `artists.get` throwing exception "type 'double' is not a subtype of type 'int?' in type cast" #193

Closed KRTirtho closed 9 months ago

KRTirtho commented 10 months ago

artists.get("artist-id") is throwing

#0      _$FollowersFromJson (package:spotify/src/models/_models.g.dart:513:27)
#1      new Followers.fromJson (package:spotify/src/models/followers.dart:12:7)
#2      _$ArtistFromJson (package:spotify/src/models/_models.g.dart:345:19)
#3      new Artist.fromJson (package:spotify/src/models/artist.dart:11:57)
#4      Artists.get (package:spotify/src/endpoints/artists.dart:18:19)
<asynchronous suspension>
#5      _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
<asynchronous suspension>
#6      Retryer.retryOperation (package:fl_query/src/core/mixins/retryer.dart:17:7)
<asynchronous suspension>
#7      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)
<asynchronous suspension>

Maybe Spotify changed their followers data type to double. Although why would they count people in fractions?

hayribakici commented 10 months ago

This is very strange. The API documentation says the total is an int. I also called the API and tested the current code with the "Regal Lily" artist as mentioned in KRTIrho/spotube#1018, it returns me an int. Moreover, the code runs without any errors. Maybe spotify changed the API again in the meantime the bug has been reported (?). Othewise there is no way to reproduce the problem.

KRTirtho commented 10 months ago

So in theory, KRTirtho/spotube#1018 shouldn't happen in your case.

hayribakici commented 10 months ago

@KRTirtho So far, yes.

armanleft commented 10 months ago

What about getting followers.total as a string and show it as string too! or stringify it! I'm not familiar with Dart, it's just a suggestion.

hayribakici commented 10 months ago

@armanleft the API shows the follower.total as an int. I think it would be better to reflect the API as good as possible. Plus, the root cause of this problem is not known.

Stringifying sounds more of a hack, tbh.

KRTirtho commented 10 months ago

Looks like artist Image's height and width also has the same issue. Can we use the num type for the critical fields?

KRTirtho commented 10 months ago

Same goes for Artist.popularity

hayribakici commented 10 months ago

@KRTirtho There are two (1, 2) forum entries regarding this issue. I am marking this issue as a spotify issue. It would make sense to change the attributes into num in the short run. What do you think @rinukkusu ?

EndsM commented 10 months ago

This is strange considering the spotify API didn't seems made any changes. Maybe check the jsonString got from request, and see what's the value of map in next line is, I wonder if the dart's object from json process have any changes that may take number as double as default even the original json is straight up int

EndsM commented 10 months ago

This is truely strange indeed, I clone to repo to a codespace and create a spotify api key to test it, but I got the artist response json like this:

{
  "external_urls": {
    "spotify": "https://open.spotify.com/artist/7ucOhItVkxNqunNLo8AkzN"
  },
  "followers": {
    "href": null,
    "total": 220081
  },
  "genres": [
    "anime",
    "j-pixie"
  ],
  "href": "https://api.spotify.com/v1/artists/7ucOhItVkxNqunNLo8AkzN",
  "id": "7ucOhItVkxNqunNLo8AkzN",
  "images": [
    {
      "height": 640,
      "url": "https://i.scdn.co/image/ab6761610000e5ebeb093646d4d8309532b49d6e",
      "width": 640
    },
    {
      "height": 320,
      "url": "https://i.scdn.co/image/ab67616100005174eb093646d4d8309532b49d6e",
      "width": 320
    },
    {
      "height": 160,
      "url": "https://i.scdn.co/image/ab6761610000f178eb093646d4d8309532b49d6e",
      "width": 160
    }
  ],
  "name": "fripSide",
  "popularity": 49,
  "type": "artist",
  "uri": "spotify:artist:7ucOhItVkxNqunNLo8AkzN"
}

And the artist object is successfully created from json mapping. There are no double type value existed during the process, this is truely strange.

Dart version: 3.2.4 convert package version: 3.1.1

EndsM commented 10 months ago

But according to forum posts you mentioned earlier, it seems indeed something changed in spotify backend during this period, I assume they did something unintentional of intentional to it, but changed it back at least at this moment.

EndsM commented 10 months ago

The funny part is that, I can't find any way to recreate the problem in my environment with my own API key, no matter where I test it (using code or curl in different machines). While spotube on my phone will still get the same problem, which I assume still getting the json with float number.

This make me thinking, which is very unlikely and crazy, is spotify API sending different data result to client with different client ID (application), which cause certain application still getting wrong data?

The scenario might be some instance in the spotify web API cluster is running problem version of API, while newer or other nodes is running normal version of API. And while I create the API Key, it is handled by node that is normal.

KRTirtho commented 10 months ago

This make me thinking, which is very unlikely and crazy, is spotify API sending different data result to client with different client ID (application), which cause certain application still getting wrong data?

I don't think that's what is happening. Because once you log in with your account, Spotube solely uses the access token. The client id is no longer needed or supplied for use.

The scenario might be some instance in the spotify web API cluster is running problem version of API, while newer or other nodes is running normal version of API. And while I create the API Key, it is handled by node that is normal.

Yup, this is probably the reason.

hayribakici commented 10 months ago

Does anyone know which attributes are affected? I currently have Images.height, Images.width, Followers.total,...?

KRTirtho commented 10 months ago

Does anyone know which attributes are affected? I currently have Images.height, Images.width, Followers.total,...?

popularity as well

Jeraimee commented 10 months ago

Wanted to report that this is still happening.

hayribakici commented 10 months ago

@Jeraimee According to spotify, this issue is currently worked on.

drooxie commented 9 months ago

@Jeraimee According to spotify, this issue is currently worked on.

From the comment:

Also, our Tech folks are known for their hard work so this will be fixed in no time! Consider this issue resolved.

Yep, the issue is still present after 10 days :) Looks like their hardworking team is kinda busy for now...

rinukkusu commented 9 months ago

This is temporarly "fixed" now in v0.13.0 thanks to @hayribakici :laughing:

KRTirtho commented 9 months ago

Now, album.tracks endpoint's Paging is also infected. It says it's the limit, but I doubt it's happening for every int type fields

#0      _$PagingFromJson (package:spotify/src/models/_models.g.dart:523:27)
#1      new Paging.fromJson (package:spotify/src/models/paging.dart:44:57)
#2      Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart:240:20)
<asynchronous suspension>
#3      AlbumQueries.tracksOfJob.<anonymous closure> (package:spotube/services/queries/album.dart:45:11)
<asynchronous suspension>
#4      _AsyncCompleter.complete (dart:async/future_impl.dart:41:3)
<asynchronous suspension>
#5      Retryer.retryOperation (package:fl_query/src/core/mixins/retryer.dart:17:7)
<asynchronous suspension>
#6      CancelableCompleter.complete.<anonymous closure> (package:async/src/cancelable_operation.dart:425:16)
<asynchronous suspension>