Skip to content

Commit 8ff18e8

Browse files
committed
use django checks system
1 parent 2be4451 commit 8ff18e8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

oauth2_provider/checks.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from django.apps import apps
2+
from django.core import checks
3+
from django.db import router
4+
5+
from .settings import oauth2_settings
6+
7+
8+
@checks.register(checks.Tags.database)
9+
def validate_token_configuration(app_configs, **kwargs):
10+
breakpoint()
11+
databases = set(
12+
router.db_for_write(apps.get_model(model))
13+
for model in (
14+
oauth2_settings.ACCESS_TOKEN_MODEL,
15+
oauth2_settings.ID_TOKEN_MODEL,
16+
oauth2_settings.REFRESH_TOKEN_MODEL,
17+
)
18+
)
19+
20+
# This is highly unlikely, but let's warn people just in case it does.
21+
# If the tokens were allowed to be in different databases this would require all
22+
# writes to have a transaction around each database. Instead, let's enforce that
23+
# they all live together in one database.
24+
# The tokens are not required to live in the default database provided the Django
25+
# routers know the correct database for them.
26+
if len(databases) > 1:
27+
return [checks.Error("The token models are expected to be stored in the same database.")]
28+
29+
return []

0 commit comments

Comments
 (0)