Skip to content

Commit d58025f

Browse files
committed
fix: add json.loads guard to plotusers, ensure points key in update route, remove duplicate import
1 parent 9c5b57c commit d58025f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

ide/routes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from io import BytesIO
3535
import zipfile
3636
import cgi
37-
import datetime
3837
import uuid
3938
import flask
4039
import traceback
@@ -227,9 +226,12 @@ def plotusers():
227226
history_setting = ndb.Key('Setting', 'user_count_history').get()
228227
if not history_setting or history_setting.value == 'NOT SET':
229228
return flask.render_template('plotusers.html', points=[], updated=None, no_data=True)
230-
history = json.loads(history_setting.value)
229+
try:
230+
history = json.loads(history_setting.value)
231+
except (json.JSONDecodeError, ValueError):
232+
return flask.render_template('plotusers.html', points=[], updated=None, no_data=True)
231233
return flask.render_template('plotusers.html',
232-
points=history['points'],
234+
points=history.get('points', []),
233235
updated=history.get('updated'),
234236
no_data=False)
235237

@@ -250,6 +252,8 @@ def update_user_count():
250252
else:
251253
try:
252254
history = json.loads(history_setting.value)
255+
if 'points' not in history:
256+
history['points'] = []
253257
except (json.JSONDecodeError, ValueError):
254258
history = {'points': []}
255259

0 commit comments

Comments
 (0)