mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #32224 -- Avoided suppressing connection errors in supports_json_field on SQLite.`
Regression in 6789ded0a6
.
Thanks Juan Garcia Alvite for the report.
This commit is contained in:
parent
b996424199
commit
f5e5aac59e
@ -70,11 +70,12 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def supports_json_field(self):
|
def supports_json_field(self):
|
||||||
try:
|
with self.connection.cursor() as cursor:
|
||||||
with self.connection.cursor() as cursor, transaction.atomic():
|
try:
|
||||||
cursor.execute('SELECT JSON(\'{"a": "b"}\')')
|
with transaction.atomic(self.connection.alias):
|
||||||
except OperationalError:
|
cursor.execute('SELECT JSON(\'{"a": "b"}\')')
|
||||||
return False
|
except OperationalError:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
can_introspect_json_field = property(operator.attrgetter('supports_json_field'))
|
can_introspect_json_field = property(operator.attrgetter('supports_json_field'))
|
||||||
|
@ -24,3 +24,7 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a regression in Django 3.1 that caused the incorrect grouping by a
|
* Fixed a regression in Django 3.1 that caused the incorrect grouping by a
|
||||||
``Q`` object annotation (:ticket:`32200`).
|
``Q`` object annotation (:ticket:`32200`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 3.1 that caused suppressing connection errors
|
||||||
|
when :class:`~django.db.models.JSONField` is used on SQLite
|
||||||
|
(:ticket:`32224`).
|
||||||
|
18
tests/backends/sqlite/test_features.py
Normal file
18
tests/backends/sqlite/test_features.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from unittest import mock, skipUnless
|
||||||
|
|
||||||
|
from django.db import OperationalError, connection
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@skipUnless(connection.vendor == 'sqlite', 'SQLite tests.')
|
||||||
|
class FeaturesTests(TestCase):
|
||||||
|
def test_supports_json_field_operational_error(self):
|
||||||
|
if hasattr(connection.features, 'supports_json_field'):
|
||||||
|
del connection.features.supports_json_field
|
||||||
|
msg = 'unable to open database file'
|
||||||
|
with mock.patch(
|
||||||
|
'django.db.backends.base.base.BaseDatabaseWrapper.cursor',
|
||||||
|
side_effect=OperationalError(msg),
|
||||||
|
):
|
||||||
|
with self.assertRaisesMessage(OperationalError, msg):
|
||||||
|
connection.features.supports_json_field
|
Loading…
Reference in New Issue
Block a user