From d9088b410e3fe9193bb85dfe9f263de8e87aecac Mon Sep 17 00:00:00 2001 From: catborise Date: Sat, 24 Oct 2026 23:20:23 +0300 Subject: [PATCH] fix(accounts): knox creates no table of its own knox's first migration creates its AuthToken table even when KNOX_TOKEN_MODEL replaces it with accounts.ApiToken. The unused knox_authtoken table references auth_user, and Django, which does not see it, does not empty it with the others: on PostgreSQL every test that empties the database failed ("cannot truncate a table referenced in a foreign key constraint"). SQLite does not check this, so only CI's PostgreSQL leg showed it. knox stays installed for its token code, with its migrations turned off (MIGRATION_MODULES). --- accounts/tests/test_api_tokens.py | 7 +++++++ webvirtcloud/settings.py.template | 3 +++ 2 files changed, 10 insertions(+) diff --git a/accounts/tests/test_api_tokens.py b/accounts/tests/test_api_tokens.py index bcf2314e..44ff822d 100644 --- a/accounts/tests/test_api_tokens.py +++ b/accounts/tests/test_api_tokens.py @@ -6,6 +6,7 @@ from datetime import timedelta from accounts.models import ApiToken from django.contrib.auth import get_user_model +from django.db import connection from django.test import TestCase from django.urls import reverse from django.utils import timezone @@ -91,3 +92,9 @@ class ApiTokenTests(TestCase): response = self.client.post(reverse("accounts:api_token_create"), {"name": " ", "days": "30"}) self.assertFalse(ApiToken.objects.exists()) self.assertNotRegex(response.content.decode(), r"wvc_[0-9a-f]{64}") + + def test_knox_makes_no_table_of_its_own(self): + # accounts.ApiToken replaces knox's AuthToken; a knox_authtoken table + # would reference auth_user unseen, and PostgreSQL could not empty + # auth_user between tests + self.assertNotIn("knox_authtoken", connection.introspection.table_names()) diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index daa82ed4..d29e8006 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -381,6 +381,9 @@ REST_FRAMEWORK = { # "Authorization: Token wvc_..."; made and deleted on the profile page KNOX_TOKEN_MODEL = "accounts.ApiToken" REST_KNOX = {"TOKEN_PREFIX": "wvc_"} +# knox stays installed for its token code, but its migrations would create a +# knox_authtoken table that accounts.ApiToken replaces +MIGRATION_MODULES = {"knox": None} SPECTACULAR_SETTINGS = { "TITLE": "Webvirtcloud REST-API",