discogs icon indicating copy to clipboard operation
discogs copied to clipboard

[DEPRECATED]: The key 'count' has been replaced with 'total'.

Open rtuz2th opened this issue 7 years ago • 15 comments

Hi, first of all, thanks for the great work you all, I really love this wrapper, using it for all my applications, makes it way easier for me. I'm just working with this piece of code:

require 'discogs-wrapper' require 'pp' aw = Discogs::Wrapper.new("My_Application", user_token: "My_Token") path='Path to my CSV File with Label ID's of Records' seperator = ',' values = File.open(path).map{|line| line.chop.split(seperator)} temp_data=aw.search(values[0][0])["results"][0] pp aw.get_release(temp_data['id'])['status']

Got this as return: [DEPRECATED]: The key 'count' has been replaced with 'total'. When accessing, please use the latter. This message will be removed in the next major release. W, [2018-01-15T19:29:26.463127 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#count defined in Enumerable. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.467639 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.469200 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.469642 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.470643 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.471159 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.471644 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.472192 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.472653 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.473155 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method. W, [2018-01-15T19:29:26.473653 #12056] WARN -- : You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.

To be honest I'm not really sure what this means to me, I'm pretty new to ruby, but as far as I can see I did not mess with Syntax or Discogs own structure, or did I just get something wrong? Thank you very much! Greetings, rtuz2th

rtuz2th avatar Jan 15 '18 18:01 rtuz2th

Hey there, thanks for the comments.

This is a warning that the library produces when you use the "count" key in a response. This name conflicts with a Ruby native method and thus can cause conflicts.

Are you using "count" anywhere in your app when dealing with responses from Discogs? If so, swap them out with "total" and the warnings will go away.

Also note, these are warnings and will not break your app.

buntine avatar Jan 22 '18 00:01 buntine

I noticed that they don't break my application, I just used the source code posted above. Just thought I'll post it here, I have never had any issues with this wrapper, using it for small applications for my record store, thank you very much again!

rtuz2th avatar Jan 22 '18 15:01 rtuz2th

Okay, I've been playing around with this. While obviously the deprecated warning and the subsequent warnings about "count" from Hashie are expected in the current version, there is another clashing key, as alluded to in OP's output. Each track in the tracklist (itself a hash) has a "type_" key, which Hashie doesn't like. This should be easy enough to fix in that it's just another conflict to add to the sanitize_hash method (the right replacement key is maybe no so clear).

def sanitize_hash(hash)
    conflicts = {"count" => "total", "type_" => "kind"}
    result = {}

    for k, v in hash
      safe_name = conflicts[k]

      if safe_name
        result[safe_name] = v
        k = safe_name
      else
        result[k] = v
      end

      if v.is_a?(Hash)
        result[k] = sanitize_hash(result[k])
      end
    end

    result
  end

The recursive "sanitization" in sanitize_hash doesn't work for tracklists, though, because they are arrays of hashes. I'm not sure what the most elegant way to deal with that is.

The upshot is that as is the fix won't stop the warnings once you drop the temporary deprecation notice because any album for which there is a tracklist will trigger one warning per track.

jacob-long avatar Feb 03 '18 18:02 jacob-long

Thanks Jacob.

I will pudate the sanitize_hash method and test it with the tracks. As for the recursive function, I will need to extend it to also account for arrays.

buntine avatar Feb 06 '18 00:02 buntine

Looks great guys, thank you very much! Recursive functions are definetely over the top for me, everything I learned about ruby is just what I googled to build applications for my personal needs. Thank you for your work, looking forward to the update!

rtuz2th avatar Feb 06 '18 11:02 rtuz2th

Hey guys, any updates on this issue being implemented to fix the warnings?

atebit avatar Oct 03 '18 23:10 atebit

I am a bit stuffed for time for the next week. I am open to PRs, of course.

Otherwise, I plan to take a look at this in about one week. Thanks for the reminder!

buntine avatar Oct 04 '18 01:10 buntine

Hey everyone, I'm trying to build a CLI app using the Discogs Wrapper and I keep getting the following message filling up my terminal window.

[DEPRECATED]: The key 'count' has been replaced with 'total'. When accessing, please use the latter. This message will be removed in the next major release.

Does anyone have some advice on how to ignore these messages from being put to the terminal? Would really appreciate any help, thanks!

DavidOliverius avatar Apr 21 '22 01:04 DavidOliverius

Are you certain you're using the latest version of the gem? It should be 2.5.1. My code that uses the wrapper requires that version, and don't see the deprecation warnings anymore.

jslabovitz avatar Apr 22 '22 11:04 jslabovitz

Hi there, I am using version 2.5.1. Every time I search the API for a specific release, I got one of the error messages for each number of tracks on that specific release.

DavidOliverius avatar Apr 22 '22 11:04 DavidOliverius

If you can narrow down your code to a script with a few lines, and post it here, I can try it on my end. (Don't post your user/token; I'll plug mine in instead.)

jslabovitz avatar Apr 22 '22 12:04 jslabovitz

release = wrapper.get_release(1)
puts "'#{release['title']}' - #{release['artists'][0]['name']}, released #{release['released_formatted']}"

I am also getting Hashie errors that seem to coincide with the 'DEPRECATED' warnings.

DavidOliverius avatar Apr 22 '22 12:04 DavidOliverius

Sigh. Yes, I'm getting the same errors that you are. Sorry, I thought I was immune, but I guess not. Maybe @buntine can weigh in?

jslabovitz avatar Apr 22 '22 13:04 jslabovitz

I appreciate you looking into it @jslabovitz - glad to know it's not just me though!

DavidOliverius avatar Apr 22 '22 13:04 DavidOliverius