seitime-frappe/frappe/patches/v15_0/migrate_session_data.py
Ankush Menat 7a854efc03
refactor: Use JSON for session data (#25207)
JSON is proper format compared to using safe_eval which is a hack to convert
string repr of dict object back into python object.
2024-03-04 06:47:48 +00:00

24 lines
663 B
Python

import frappe
from frappe.utils import update_progress_bar
def execute():
frappe.db.auto_commit_on_many_writes = True
Sessions = frappe.qb.DocType("Sessions")
current_sessions = (frappe.qb.from_(Sessions).select(Sessions.sid, Sessions.sessiondata)).run(
as_dict=True
)
for i, session in enumerate(current_sessions):
try:
new_data = frappe.as_json(frappe.safe_eval(session.sessiondata))
except Exception:
# Rerunning patch or already converted.
continue
(
frappe.qb.update(Sessions).where(Sessions.sid == session.sid).set(Sessions.sessiondata, new_data)
).run()
update_progress_bar("Patching sessions", i, len(current_sessions))