Skip to content

Commit

Permalink
Avoid blacklisting app migrations failing in projects with multiple d…
Browse files Browse the repository at this point in the history
…atabases (#429)

* add a second database for tests as an indicator that migrations for the blacklisting app will run with no issues in projects with multiple databases

* set the db_alias when migrating the jti claim to avoid migrations failing in projects with multiple databases
  • Loading branch information
ghazi-git committed Jun 27, 2021
1 parent 110deb0 commit 6520278
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
def populate_jti_hex(apps, schema_editor):
OutstandingToken = apps.get_model('token_blacklist', 'OutstandingToken')

for token in OutstandingToken.objects.all():
db_alias = schema_editor.connection.alias
for token in OutstandingToken.objects.using(db_alias).all():
token.jti_hex = token.jti.hex
token.save()


def reverse_populate_jti_hex(apps, schema_editor): # pragma: no cover
OutstandingToken = apps.get_model('token_blacklist', 'OutstandingToken')

for token in OutstandingToken.objects.all():
db_alias = schema_editor.connection.alias
for token in OutstandingToken.objects.using(db_alias).all():
token.jti = UUID(hex=token.jti_hex)
token.save()

Expand Down
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def pytest_configure():
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
},
'other': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'other'
}
},
SITE_ID=1,
Expand Down

0 comments on commit 6520278

Please sign in to comment.