I am using django-tenent
and rest_framework_simplejwt
and i had no any issue until I implemented rest_framework_simplejwt.token_blacklist
then it started to give me errors like:
django.db.utils.IntegrityError: insert or update on table "token_blacklist_outstandingtoken" violates foreign key constraint "token_blacklist_outs_user_id_83bc629a_fk_authusers"
DETAIL: Key (user_id)=(1b87717c-e91e-4049-8e89-5db9dbef4015) is not present in table "authusers_customuser".
Project configuration
In settings.py
SHARED_APPS = (
'django_tenants',
'tenants.apps.TenantsConfig',
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authusers.apps.AuthusersConfig',
'rest_framework',
'corsheaders',
'rest_framework_simplejwt',
'rest_framework_simplejwt.token_blacklist',
)
TENANT_APPS = (
'django.contrib.contenttypes',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authusers.apps.AuthusersConfig',
... # my apps
)
REST_FRAMEWORK = {
"NON_FIELD_ERROR_KEY": "error",
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework_simplejwt.authentication.JWTAuthentication",
),
}
# Rest-restframework jwt validation token lifetime
SIMPLE_JWT = {
"TOKEN_OBTAIN_SERIALIZER": "authusers.serializers.CustomTokenObtainPairSerializer",
"ACCESS_TOKEN_LIFETIME": timedelta(hours=12),
"REFRESH_TOKEN_LIFETIME": timedelta(days=3),
}
I am using all the things provided by package for login, refresh, verify in urls.py
from rest_framework_simplejwt.views import (
TokenRefreshView, TokenBlacklistView, TokenObtainPairView,
TokenVerifyView
)
path('login/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('token/verify/', TokenVerifyView.as_view(), name='token_verify'),
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
All was going smoothly until i added 'rest_framework_simplejwt.token_blacklist'
in SHARED_APP
then it asked for migration which i migrated then i tried logging, it started to show above error message.
I did some research a found this issue in github and tried installing in TENENT_APP
still had the same issue.
I am like confused why is the sub-domain isn't redirecting the blacklist token to the correct schema. I am using single db multiple schema, all the request are being redirected to the correct schema on the database except those urls. Now all those are using public tenant db to look for user and perform action.
What i am assuming from the error above is that while performing those actions package is now looking in correct schema even though i have used sub-domain url for logging in.