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

Conversion error when migrating token_blacklist app. #131

Open
AutumnalDream opened this issue Jul 2, 2019 · 3 comments
Open

Conversion error when migrating token_blacklist app. #131

AutumnalDream opened this issue Jul 2, 2019 · 3 comments

Comments

@AutumnalDream
Copy link

When running the initial migrations for the token_blacklist app I would get this message.

File "/venv/lib/python3.7/site-packages/rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py", line 10, in populate_jti_hex
    token.jti_hex = token.jti.hex
AttributeError: 'str' object has no attribute 'hex'

So in that specific migration there is this code.

for token in OutstandingToken.objects.all():
        token.jti_hex = token.jti.hex
        token.save()

I changed it to this and now it works.

for token in OutstandingToken.objects.all():
        token.jti_hex = binascii.hexlify(bytes(token.jti, "utf-8"))
        token.save()
@JaniL
Copy link

JaniL commented Mar 24, 2020

Hey, we started using this library in our project and stumbled on this same issue as well with @JoonatanPartanen.

If we understood this correctly based on few commits we found related to this, token.jti should be a UUID object instead of str. Because of this we're seeing the error mentioned earlier since UUID has a method called hex and str does not. We're not sure why this is happening, but we do agree that this needs a pull request. Not sure if @AutumnalDream's solution is the right one though if jti changing from UUID to str is not intentional.

@jparta
Copy link

jparta commented Mar 24, 2020

There is likely some migration magic going on here. Looking at the migrations preceding this one (in the same path), OutstandingToken.jti should indeed still be a UUID object instead of a str. I am not sure what actions cause the migrations to be executed out of order (or whatever causes this).

Here is a link to the file:
https://github.com/SimpleJWT/django-rest-framework-simplejwt/blob/03656ce0c8e1868d742704f72e3cf17b3d5b5b33/rest_framework_simplejwt/token_blacklist/migrations/0003_auto_20171017_2007.py

There is a rejected commit that seems to try to fix this:
de27294#diff-0163daaef412efb1451cadacef906469

@codertron3000
Copy link

codertron3000 commented Jul 2, 2024

I tried the following and the migration worked:

for token in OutstandingToken.objects.all():
        token.jti_hex = UUID(token.jti).hex
        token.save()

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

4 participants