Skip to content

Commit 11f56e5

Browse files
committed
Handle 0-row SELECT responses properly
1 parent ca3cfed commit 11f56e5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/server/api/admin_api.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,29 @@ def list_statistics():
122122
result = connection.execute(s)
123123
last_execution_details = result.fetchone()[0]
124124

125-
126125
except Exception as e:
127-
current_app.logger.error("Failure reading Last Execution stats from DB")
128-
# return abort(500) # Weird but not worth a 500
126+
current_app.logger.warning("Failure reading Last Execution stats from DB")
127+
# Will heppen on first run, shouldn't after
129128

130129
return last_execution_details
131130

132131

133132
@admin_api.route("/api/get_execution_status/<int:job_id>", methods=["GET"])
134133
def get_exec_status(job_id):
135-
kvt = Table("kv_unique", metadata, autoload=True, autoload_with=engine)
134+
""" Get the execution status record from the DB for the specified job_id """
135+
kvt = Table("kv_unique", metadata, autoload=True, autoload_with=engine) #TODO: Don't think we need this or Metadata import
136+
137+
exec_status = '{}'
138+
136139
with engine.connect() as connection:
137140
s_jobid = 'job-' + str(job_id)
138141
s = text("select valcol from kv_unique where keycol = :j ;")
139142
s = s.bindparams(j=s_jobid)
140143
result = connection.execute(s)
141-
exec_status = result.fetchone()[0]
144+
if result.rowcount > 0:
145+
exec_status = result.fetchone()[0]
146+
else:
147+
current_app.logger.warning("Failure reading Execution Status from DB")
142148

143149
return exec_status
144150

0 commit comments

Comments
 (0)