Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

AttributeError: 'dict' object has no attribute 'id' #115

Open
sobolevn opened this issue Feb 15, 2017 · 4 comments
Open

AttributeError: 'dict' object has no attribute 'id' #115

sobolevn opened this issue Feb 15, 2017 · 4 comments

Comments

@sobolevn
Copy link

When passing {'id': 'someId'} into the _default_jwt_payload_handler it raises an exception.

The problem is in this expression: identity = getattr(identity, 'id') or identity['id']
https://github.com/mattupstate/flask-jwt/blob/master/flask_jwt/__init__.py#L53

It must be: identity = getattr(identity, 'id', None) or identity['id']

@daverbj
Copy link

daverbj commented Dec 9, 2017

I have a user model looks like this

class UserModel(db.Model):
    __tablename__ = 'b_users'
    ID = db.Column(db.Integer, primary_key=True)
    user_login = db.Column(db.String(120), nullable=False)
    user_pass = db.Column(db.String(120), nullable=False)
    user_nicename = db.Column(db.String(120), nullable=False)
    user_email = db.Column(db.String(120), nullable=False)
    user_url = db.Column(db.String(120), nullable=False)
    user_registered = db.Column(db.String(120), nullable=False)
    user_activation_key = db.Column(db.String(120), nullable=False)
    user_status = db.Column(db.Integer, nullable=False)
    display_name = db.Column(db.String(120), nullable=False)

instead of id I have ID in the object so I get

identity = getattr(identity, 'id') or identity['id']
AttributeError: 'UserModel' object has no attribute 'id'

Is there any work around to use custom id field in identity object ?

@sobolevn
Copy link
Author

sobolevn commented Dec 9, 2017

I have just created a class instead of a dict to store my id as a property.

@Kartstig
Copy link

Kartstig commented Feb 3, 2020

I'm also getting this error. I'm using namedtuple as a workaround

@bartgenuit
Copy link

bartgenuit commented Jun 28, 2021

I would also like to use another property name, since id is a Python built-in function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants