File tree Expand file tree Collapse file tree
django/db/backends/sqlite3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,11 +54,12 @@ class DatabaseFeatures(BaseDatabaseFeatures):
5454
5555 @cached_property
5656 def supports_json_field (self ):
57- try :
58- with self .connection .cursor () as cursor , transaction .atomic ():
59- cursor .execute ('SELECT JSON(\' {"a": "b"}\' )' )
60- except OperationalError :
61- return False
57+ with self .connection .cursor () as cursor :
58+ try :
59+ with transaction .atomic (self .connection .alias ):
60+ cursor .execute ('SELECT JSON(\' {"a": "b"}\' )' )
61+ except OperationalError :
62+ return False
6263 return True
6364
6465 can_introspect_json_field = property (operator .attrgetter ('supports_json_field' ))
Original file line number Diff line number Diff line change @@ -24,3 +24,7 @@ Bugfixes
2424
2525* Fixed a regression in Django 3.1 that caused the incorrect grouping by a
2626 ``Q`` object annotation (:ticket:`32200`).
27+
28+ * Fixed a regression in Django 3.1 that caused suppressing connection errors
29+ when :class:`~django.db.models.JSONField` is used on SQLite
30+ (:ticket:`32224`).
Original file line number Diff line number Diff line change 1+ from unittest import mock , skipUnless
2+
3+ from django .db import OperationalError , connection
4+ from django .test import TestCase
5+
6+
7+ @skipUnless (connection .vendor == 'sqlite' , 'SQLite tests.' )
8+ class FeaturesTests (TestCase ):
9+ def test_supports_json_field_operational_error (self ):
10+ if hasattr (connection .features , 'supports_json_field' ):
11+ del connection .features .supports_json_field
12+ msg = 'unable to open database file'
13+ with mock .patch (
14+ 'django.db.backends.base.base.BaseDatabaseWrapper.cursor' ,
15+ side_effect = OperationalError (msg ),
16+ ):
17+ with self .assertRaisesMessage (OperationalError , msg ):
18+ connection .features .supports_json_field
You can’t perform that action at this time.
0 commit comments