Skip to content

Commit 738b8f7

Browse files
committed
fix: handle corrupted history JSON and replace deprecated datetime.utcnow
1 parent d64d6a4 commit 738b8f7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

ide/routes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from .models import User, Program, Folder, Setting
4949

5050
import os, re, base64
51-
from datetime import datetime
51+
from datetime import datetime, timezone
5252

5353
# URI encoding (percent-escaping of all characters other than [A-Za-z0-9-_.~]) is used for names
5454
# of users, folders and programs in the model and in URIs and in JSON, so no (un)escaping is required.
@@ -248,9 +248,12 @@ def update_user_count():
248248
elif history_setting.value == 'NOT SET':
249249
history = {'points': []}
250250
else:
251-
history = json.loads(history_setting.value)
251+
try:
252+
history = json.loads(history_setting.value)
253+
except (json.JSONDecodeError, ValueError):
254+
history = {'points': []}
252255

253-
now = datetime.utcnow()
256+
now = datetime.now(timezone.utc)
254257
history['updated'] = now.strftime('%Y-%m-%d')
255258
history['points'].append({'month': now.strftime('%Y-%m'), 'count': count})
256259

0 commit comments

Comments
 (0)