Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: load_question_answers backward compat with dict values from save_question_meta

whf1e9f2a56d568
diff --git a/deeptutor/learning/storage.py b/deeptutor/learning/storage.py
index 8a7007939..dc727424a 100644
--- a/deeptutor/learning/storage.py
+++ b/deeptutor/learning/storage.py
@@ -69,13 +69,24 @@ class LearningStore:
_atomic_write_text(path, text)
def load_question_answers(self, book_id: str) -> dict[str, str]:
- """Load question answers. Returns {} if none saved."""
+ """Load question answers. Returns {} if none saved.
+
+ Backward compatible: if a value is a dict (from save_question_meta),
+ extracts the \"answer\" key.
+ """
import json
path = self._questions_path(book_id)
if not path.exists():
return {}
- return json.loads(path.read_text(encoding="utf-8"))
+ raw = json.loads(path.read_text(encoding="utf-8"))
+ result = {}
+ for qid, val in raw.items():
+ if isinstance(val, dict):
+ result[qid] = val.get("answer", "")
+ else:
+ result[qid] = val
+ return result
def save_question_meta(self, book_id: str, meta: dict) -> None:
"""Save question metadata (answer, kp_id, module_id, question_type).