Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
-->

## [3.0.1] - 2024-09-07
### Fixed
* #1491 Fix migration error when there are pre-existing Access Tokens.

## [3.0.0] - 2024-09-05

### WARNING - POTENTIAL BREAKING CHANGES
Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.0.0"
__version__ = "3.0.1"
20 changes: 17 additions & 3 deletions oauth2_provider/migrations/0012_add_token_checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
from django.db import migrations, models
from oauth2_provider.settings import oauth2_settings

def forwards_func(apps, schema_editor):
"""
Forward migration touches every "old" accesstoken.token which will cause the checksum to be computed.
"""
AccessToken = apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
accesstokens = AccessToken._default_manager.all()
for accesstoken in accesstokens:
accesstoken.save(update_fields=['token_checksum'])


class Migration(migrations.Migration):
dependencies = [
("oauth2_provider", "0011_refreshtoken_token_family"),
Expand All @@ -14,13 +24,17 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="accesstoken",
name="token_checksum",
field=oauth2_provider.models.TokenChecksumField(
blank=True, db_index=True, max_length=64, unique=True
),
field=oauth2_provider.models.TokenChecksumField(blank=True, null=True, max_length=64),
),
migrations.AlterField(
model_name="accesstoken",
name="token",
field=models.TextField(),
),
migrations.RunPython(forwards_func, migrations.RunPython.noop),
migrations.AlterField(
model_name='accesstoken',
name='token_checksum',
field=oauth2_provider.models.TokenChecksumField(blank=False, max_length=64, db_index=True, unique=True),
),
]
2 changes: 1 addition & 1 deletion oauth2_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class AbstractAccessToken(models.Model):
token = models.TextField()
token_checksum = TokenChecksumField(
max_length=64,
blank=True,
blank=False,
unique=True,
db_index=True,
)
Expand Down
Loading