Skip to content
This repository has been archived by the owner. It is now read-only.

Spotify objects with different songs are equal in on_member_update #2113

Closed
3 tasks done
TheGrammarJew opened this issue Apr 22, 2019 · 3 comments
Closed
3 tasks done

Spotify objects with different songs are equal in on_member_update #2113

TheGrammarJew opened this issue Apr 22, 2019 · 3 comments
Labels
Milestone

Comments

@TheGrammarJew
Copy link

@TheGrammarJew TheGrammarJew commented Apr 22, 2019

Summary

When a song progresses to a different one on Spotify, on_member_update is called, but before == after, and before.activities == after.activities.

Seems to be caused by hashing the session id, which doesn't change between songs.

Reproduction Steps

@bot.event
async def on_member_update(b,a)
    print(b==a)
    print(b.activities == a.activities)

Expected Results

Output:

False
False

Actual Results

Output:

True
True

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible. N/A
  • I have removed my token from display, if visible. N/A

System Information

  • discord.py version: 1.0.1
  • Python version: 3.7.1
  • Operating system: Platform-independent (Tested on Centos 7, Win7/10)
@NCPlayz
Copy link
Contributor

@NCPlayz NCPlayz commented Apr 22, 2019

Doing a quick check reveals that comparing Member only compares the member ID and nothing else, as written here.
Assuming Member.activities has only an instance of Spotify, comparing the two only compares the session ID, as written here.

A simple way to represent this is:

class MyClass:
    def __init__(self):
        self.id = 5
        self.something_else = 2
        
    def __eq__(self, other):
        return self.id == other.id
    
my_list = [MyClass()]

m = MyClass()
m.something_else = 6
my_other_list = [m]

print(my_list == my_other_list)  # True because both instances of MyClass have the same ID

A way to work around this would be to compare the track_id of the Spotify instances instead.

Loading

@Rapptz
Copy link
Owner

@Rapptz Rapptz commented Apr 22, 2019

The behaviour of Member.__eq__ is not going to change.

However, the behaviour of Spotify.__eq__ could be better I suppose.

Loading

@Rapptz Rapptz added the bug label Apr 22, 2019
@Rapptz Rapptz added this to the v1.1 milestone May 2, 2019
@Rapptz
Copy link
Owner

@Rapptz Rapptz commented May 9, 2019

Fixed in 01588fa

Loading

@Rapptz Rapptz closed this May 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants