Skip to content

Commit 6e7b06b

Browse files
committed
BUG#35755852: Django config raise_on_warnings is ignored without isolation_level
When the Django config option `isolation_level` is not provided, the value of the option `raise_on_warnings` is ignored. This issue was fixed by adding the missing default value in the pop() function used for the `isolation_level`, which raises a `KeyError` and breaks the assignment of the options. Change-Id: I54a676b21586b94015618d16c223a60b5871221c
1 parent 387572d commit 6e7b06b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v8.2.0
1414
- WL#15664: Add support for Python 3.12
1515
- WL#15623: Improve the authentication module
1616
- WL#15218: Support WebAuthn authentication
17+
- BUG#35755852: Django config raise_on_warnings is ignored without isolation_level
1718
- BUG#35547876: C/Python 8.1.0 type check build fails in the pb2 branch
1819
- BUG#35544123: Kerberos unit tests configuration is outdated
1920
- BUG#35503506: Query on information_schema.columns returns bytes

lib/mysql/connector/django/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def get_connection_params(self) -> Dict[str, Any]:
373373

374374
try:
375375
options = settings_dict["OPTIONS"].copy()
376-
isolation_level = options.pop("isolation_level")
376+
isolation_level = options.pop("isolation_level", None)
377377
if isolation_level:
378378
isolation_level = isolation_level.lower()
379379
if isolation_level not in self.isolation_levels:

tests/test_django.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,22 @@ def test_init_command(self):
608608
cur.execute(f"SELECT @{self.var_name}")
609609
res = cur.fetchall()
610610
self.assertEqual((self.var_value,), res[0])
611+
612+
613+
class BugOra35755852(tests.MySQLConnectorTests):
614+
"""BUG#35755852: Django config raise_on_warnings is ignored without isolation_level
615+
616+
When the Django config option `isolation_level` is not provided, the
617+
value of the option `raise_on_warnings` is ignored.
618+
619+
This issue was fixed by adding the missing default value in the pop()
620+
function used for the `isolation_level`, which raises a `KeyError` and
621+
breaks the assignment of the options.
622+
"""
623+
624+
def test_missing_config(self):
625+
settings.DATABASES["default"]["OPTIONS"] = {"raise_on_warnings": True}
626+
cnx = DatabaseWrapper(settings.DATABASES["default"])
627+
cnx_params = cnx.get_connection_params()
628+
self.assertTrue(cnx_params["raise_on_warnings"])
629+
del settings.DATABASES["default"]["OPTIONS"]

0 commit comments

Comments
 (0)