-
Notifications
You must be signed in to change notification settings - Fork 813
Description
Describe the bug
The token_family field in the RefreshToken model is defined as a UUIDField, but when saving to the database, it occasionally gets stored in the full UUID string format (with hyphens, 36 characters) instead of the expected hex format (32 characters). This causes a DataError: (1406, "Data too long for column 'token_family' at row 1") when using MySQL with the column defined as VARCHAR(32).
To Reproduce
- Set up a Django project with django-oauth-toolkit and MySQL
- Configure OAuth2 provider with refresh tokens enabled
- Perform OAuth2 flows that create refresh tokens
- Occasionally, the token creation will fail with the DataErr
Expected behavior
The token_family field should consistently be saved in hex format (32 characters without hyphens) to match the UUIDField behavior and prevent database errors.
Version
django-oauth-toolkit: 3.0.1
Django: 5.0.1
Python: 3.11.13
Database: MySQL
- I have tested with the latest published release and it's still a problem.
- I have tested with the master branch and it's still a problem.
Additional context
The issue appears to be related to inconsistent handling of UUID values between Django's UUIDField and the database storage
We've implemented signals to normalize the format pre-save, but the issue persists, suggesting the problem may occur at a lower level in the library
The error occurs randomly during token creation, making it difficult to reproduce consistently
MySQL's strict mode exacerbates the issue by rejecting values that exceed the column size