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

struct.pack error creating token using custom User model with UUID as pk #102

Closed
LaundroMat opened this issue Oct 3, 2023 · 1 comment
Closed

Comments

@LaundroMat
Copy link

I'm using version ^3.2.1 and ran into the same issue as #17 when using a custom User model with a UUID as primary key.

The custom user model inherits from AbstractBaseUser and this abstract model class:

class UUIDModel(models.Model):
    id = models.UUIDField(
        primary_key=True,
        default=uuid.uuid4,
        editable=False,
        unique=True
    )

    class Meta:
        abstract = True

The error is;

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\..\.venv\lib\site-packages\sesame\utils.py:47: in get_query_string
    return "?" + urlencode({settings.TOKEN_NAME: create_token(user, scope)})
..\..\..\.venv\lib\site-packages\sesame\tokens.py:16: in create_token
    return tokens.create_token(user, scope)
..\..\..\.venv\lib\site-packages\sesame\tokens_v2.py:133: in create_token
    primary_key = packers.packer.pack_pk(getattr(user, settings.PRIMARY_KEY_FIELD))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

cls = <class 'sesame.packers.LongPacker'>
user_pk = UUID('d3b413f6-2249-4daf-92b0-c84d562db011')

    @classmethod
    def pack_pk(cls, user_pk):
>       return struct.pack(cls.fmt, user_pk)
E       struct.error: required argument is not an integer

..\..\..\.venv\lib\site-packages\sesame\packers.py:62: error

@LaundroMat
Copy link
Author

I forgot to tell Django that my custom user model was the one to return when get_user_model() is called (in other words, I didn't set AUTH_USER_MODEL in the settings).

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

No branches or pull requests

1 participant