44from django .test import TestCase , RequestFactory
55from django .contrib .admin .sites import AdminSite
66from django .contrib .auth .models import User
7+ from django .db .models .fields import NOT_PROVIDED
78from django .utils import timezone
89from django .test .utils import override_settings
910from unittest .mock import Mock , patch
@@ -152,6 +153,21 @@ def test_model_max_lengths(self):
152153
153154 self .assertEqual (len (log .api ), 1024 )
154155
156+ def test_profiling_fields_are_nullable_without_model_defaults (self ):
157+ """Profiling fields should allow NULL without adding Python defaults."""
158+ if not database_log_enabled ():
159+ self .skipTest ("Database logging is not enabled" )
160+
161+ profiling_field = self .APILogsModel ._meta .get_field ('profiling_data' )
162+ sql_query_count_field = self .APILogsModel ._meta .get_field ('sql_query_count' )
163+
164+ self .assertTrue (profiling_field .null )
165+ self .assertTrue (profiling_field .blank )
166+ self .assertIs (profiling_field .default , NOT_PROVIDED )
167+ self .assertTrue (sql_query_count_field .null )
168+ self .assertTrue (sql_query_count_field .blank )
169+ self .assertIs (sql_query_count_field .default , NOT_PROVIDED )
170+
155171
156172@override_settings (DRF_API_LOGGER_DATABASE = True )
157173class TestAdmin (TestCase ):
@@ -311,4 +327,4 @@ def test_admin_slow_api_filter(self):
311327 admin = APILogsAdmin (self .APILogsModel , self .site )
312328
313329 # Check that SlowAPIsFilter is in list_filter
314- self .assertIn (SlowAPIsFilter , admin .list_filter )
330+ self .assertIn (SlowAPIsFilter , admin .list_filter )
0 commit comments