python-social-auth / social-core

Python Social Auth - Core
BSD 3-Clause "New" or "Revised" License
850 stars 544 forks source link

TelegramAuth get_username get 'int' object is not subscriptable error #918

Closed Fleapse closed 5 months ago

Fleapse commented 5 months ago

Expected behaviour

the user should not receive errors

Actual behaviour

the user receive errors: 'int' object is not subscriptable in social_core/pipeline/user.py in get_username at line 46

Any logs, error output, etc?

'int' object is not subscriptable in social_core/pipeline/user.py in get_username at line 46

Any other comments?

if the user does not have a username in telegram, then he cannot log in

this happens because in social_core.backends.telegram.TelegramAuth if the user does not have a username, it is replaced with an id with the int type

For myself I'm going to fix it like this:

class CustomTelegramAuth(TelegramAuth):
    def get_user_details(self, response):
        first_name = response.get("first_name", "")
        last_name = response.get("last_name", "")
        fullname = f"{first_name} {last_name}".strip()
        return {
            "username": response.get("username") or str(response[self.ID_KEY]),
            "first_name": first_name,
            "last_name": last_name,
            "fullname": fullname,
        }
old
"username": response.get("username") or response[self.ID_KEY],
new
"username": response.get("username") or str(response[self.ID_KEY]),

It seems that the same thing can be done here, so that others do not experience similar problems

nijel commented 5 months ago

Can you please create a pull request with the change?

Fleapse commented 5 months ago

https://github.com/python-social-auth/social-core/pull/921 here it is