Skip to content

Commit 1e5d7cf

Browse files
authored
fix: do not raise runtime errors when checking if the MySQL backend is enabled (#182)
The edx-platform incorrectly passes `str(None)` in many places when course ID is not present. While this change silently ignores incorrect values provided by the platform, it is better than having runtime errors in production.
1 parent 0dd12e3 commit 1e5d7cf

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ Unreleased
1616

1717
*
1818

19+
0.3.3 – 2025-08-12
20+
******************
21+
22+
Fixed
23+
=====
24+
25+
* Do not raise runtime errors if an incorrect course ID is provided when
26+
checking if the MySQL backend is enabled.
27+
28+
1929
0.3.0 – 2025-04-23
2030
******************
2131

forum/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Openedx forum app.
33
"""
44

5-
__version__ = "0.3.2"
5+
__version__ = "0.3.3"

forum/backend.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def is_mysql_backend_enabled(course_id: str | None) -> bool:
1313
try:
1414
# pylint: disable=import-outside-toplevel
1515
from forum.toggles import ENABLE_MYSQL_BACKEND
16+
from opaque_keys import InvalidKeyError
1617
from opaque_keys.edx.keys import CourseKey
1718
except ImportError:
1819
return True
@@ -21,7 +22,10 @@ def is_mysql_backend_enabled(course_id: str | None) -> bool:
2122
if isinstance(course_id, CourseKey):
2223
course_key = course_id # type: ignore[unreachable]
2324
elif isinstance(course_id, str):
24-
course_key = CourseKey.from_string(course_id)
25+
try:
26+
course_key = CourseKey.from_string(course_id)
27+
except InvalidKeyError:
28+
pass
2529

2630
return ENABLE_MYSQL_BACKEND.is_enabled(course_key)
2731

0 commit comments

Comments
 (0)