Skip to content

Commit abbf4c2

Browse files
authored
Merge pull request #241 from CodeForPhilly/status_funcs_fix
Fix 0-row SELECT in get_execution_status()
2 parents b7c4cce + 58b1cc5 commit abbf4c2

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
@@ -121,23 +121,29 @@ def list_statistics():
121121
result = connection.execute(s)
122122
last_execution_details = result.fetchone()[0]
123123

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

129128
return last_execution_details
130129

131130

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

142148
return exec_status
143149

0 commit comments

Comments
 (0)