Skip to content

Commit 1d19e54

Browse files
authored
3.0.1: fix for migration error on upgrade to 3.0.0 (#1491)
1 parent f220235 commit 1d19e54

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
### Security
1515
-->
1616

17+
## [3.0.1] - 2024-09-07
18+
### Fixed
19+
* #1491 Fix migration error when there are pre-existing Access Tokens.
20+
1721
## [3.0.0] - 2024-09-05
1822

1923
### WARNING - POTENTIAL BREAKING CHANGES

oauth2_provider/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.0"
1+
__version__ = "3.0.1"

oauth2_provider/migrations/0012_add_token_checksum.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
from django.db import migrations, models
55
from oauth2_provider.settings import oauth2_settings
66

7+
def forwards_func(apps, schema_editor):
8+
"""
9+
Forward migration touches every "old" accesstoken.token which will cause the checksum to be computed.
10+
"""
11+
AccessToken = apps.get_model(oauth2_settings.ACCESS_TOKEN_MODEL)
12+
accesstokens = AccessToken._default_manager.all()
13+
for accesstoken in accesstokens:
14+
accesstoken.save(update_fields=['token_checksum'])
15+
16+
717
class Migration(migrations.Migration):
818
dependencies = [
919
("oauth2_provider", "0011_refreshtoken_token_family"),
@@ -14,13 +24,17 @@ class Migration(migrations.Migration):
1424
migrations.AddField(
1525
model_name="accesstoken",
1626
name="token_checksum",
17-
field=oauth2_provider.models.TokenChecksumField(
18-
blank=True, db_index=True, max_length=64, unique=True
19-
),
27+
field=oauth2_provider.models.TokenChecksumField(blank=True, null=True, max_length=64),
2028
),
2129
migrations.AlterField(
2230
model_name="accesstoken",
2331
name="token",
2432
field=models.TextField(),
2533
),
34+
migrations.RunPython(forwards_func, migrations.RunPython.noop),
35+
migrations.AlterField(
36+
model_name='accesstoken',
37+
name='token_checksum',
38+
field=oauth2_provider.models.TokenChecksumField(blank=False, max_length=64, db_index=True, unique=True),
39+
),
2640
]

oauth2_provider/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class AbstractAccessToken(models.Model):
392392
token = models.TextField()
393393
token_checksum = TokenChecksumField(
394394
max_length=64,
395-
blank=True,
395+
blank=False,
396396
unique=True,
397397
db_index=True,
398398
)

0 commit comments

Comments
 (0)