Skip to content
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

Spotify objects with different songs are equal in on_member_update #2113

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

Comments

@TheGrammarJew
Copy link

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

This comment has been minimized.

Copy link
Contributor

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.

@Rapptz

This comment has been minimized.

Copy link
Owner

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.

@Rapptz Rapptz added the bug label Apr 22, 2019

@Rapptz Rapptz added this to the v1.1 milestone May 2, 2019

@Rapptz

This comment has been minimized.

Copy link
Owner

commented May 9, 2019

Fixed in 01588fa

@Rapptz Rapptz closed this May 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.