Skip to content

Commit 94e7ae5

Browse files
rootclaude
authored andcommitted
Fix: upload endpoint database API calls
- Change db.execute() to db.execute_query() for SELECT queries - Change db.execute() to db.execute_commit() for INSERT/UPDATE/DELETE - Fix table name from 'calls' to 'call_records' - Remove db.close() call (handled by Flask app context) - Use current_app.config['db'] instead of creating new instance Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bbdcc02 commit 94e7ae5

3 files changed

Lines changed: 26 additions & 27 deletions

File tree

routes/api/call_upload.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def call_upload():
167167
return _err(str(e), 422)
168168

169169
# Apply post-tone delay (skip first N seconds of audio before saving/processing)
170-
system_row = db.execute("SELECT post_tone_delay FROM radio_systems WHERE radio_system_id = ?", (radio_system_id,)).fetchone()
170+
system_res = db.execute_query("SELECT post_tone_delay FROM radio_systems WHERE radio_system_id = ?", (radio_system_id,), fetch_mode="one")
171+
system_row = system_res.get("result") if system_res.get("success") else None
171172
post_tone_delay = int(system_row["post_tone_delay"]) if system_row else 0
172173
if post_tone_delay > 0 and len(audio_segment) > post_tone_delay * 1000:
173174
delay_ms = post_tone_delay * 1000
@@ -2306,56 +2307,56 @@ def reprocess_call_tones(call_id):
23062307
route_logger = logging.getLogger('icad_dispatch.call_upload')
23072308
route_logger.info("Reprocess tones for call_id=%s", call_id)
23082309

2309-
db = SQLiteDatabase()
2310+
db = current_app.config["db"]
23102311
try:
2311-
call_row = db.execute(
2312-
"SELECT radio_system_id, talkgroup, audio_file, start_epoch, duration FROM calls WHERE call_id = ?",
2313-
(call_id,)
2314-
).fetchone()
2315-
2312+
call_res = db.execute_query(
2313+
"SELECT radio_system_id, talkgroup, audio_file, start_epoch, duration FROM call_records WHERE call_id = ?",
2314+
(call_id,),
2315+
fetch_mode="one"
2316+
)
2317+
call_row = call_res.get("result") if call_res.get("success") else None
2318+
23162319
if not call_row:
23172320
return jsonify({"error": "Call not found"}), 404
2318-
2321+
23192322
radio_system_id = call_row["radio_system_id"]
23202323
audio_file = call_row["audio_file"]
2321-
2324+
23222325
audio_path = Path(audio_file)
23232326
if not audio_path.is_absolute():
23242327
audio_path = Path("static/audio") / audio_path
2325-
2328+
23262329
if not audio_path.exists():
23272330
return jsonify({"error": "Audio file not found"}), 404
2328-
2331+
23292332
tone_cfg = _load_tone_cfg(db, radio_system_id)
23302333
if not tone_cfg.get("tone_detection_enabled"):
23312334
return jsonify({"error": "Tone detection not enabled for this system"}), 400
2332-
2335+
23332336
audio_segment = AudioSegment.from_file(str(audio_path))
2334-
2337+
23352338
detect_result = tone_detect(
23362339
audio_segment,
23372340
tone_cfg.get("sample_rate", 8000),
23382341
tone_cfg.get("min_tone_duration", 0.05),
23392342
tone_cfg.get("freq_min", 0),
23402343
tone_cfg.get("freq_max", 4000),
23412344
)
2342-
2343-
db.execute("DELETE FROM call_tone_events WHERE call_id = ?", (call_id,))
2344-
db.execute("DELETE FROM tone_trigger_map WHERE call_id = ?", (call_id,))
2345-
2345+
2346+
db.execute_commit("DELETE FROM call_tone_events WHERE call_id = ?", (call_id,))
2347+
db.execute_commit("DELETE FROM tone_trigger_map WHERE call_id = ?", (call_id,))
2348+
23462349
for tone in detect_result.tones:
2347-
db.execute("""
2348-
INSERT INTO call_tone_events
2350+
db.execute_commit("""
2351+
INSERT INTO call_tone_events
23492352
(call_id, start_time, end_time, frequency_a, frequency_b, tone_type, matched_trigger_id)
23502353
VALUES (?, ?, ?, ?, ?, ?, NULL)
23512354
""", (call_id, tone.start_time, tone.end_time, tone.freq_a, tone.freq_b, tone.tone_type))
2352-
2353-
db.execute(
2354-
"UPDATE calls SET tone_count = ? WHERE call_id = ?",
2355-
(len(detect_result.tones), call_id)
2355+
2356+
db.execute_commit(
2357+
"UPDATE call_records SET has_tone = 1 WHERE call_id = ?",
2358+
(call_id,)
23562359
)
2357-
2358-
db.commit()
23592360
route_logger.info("Reprocessed %d tones for call_id=%s", len(detect_result.tones), call_id)
23602361

23612362
return jsonify({
@@ -2367,5 +2368,3 @@ def reprocess_call_tones(call_id):
23672368
except Exception as e:
23682369
route_logger.error("Reprocess failed for call_id=%s: %s\n%s", call_id, e, traceback.format_exc())
23692370
return jsonify({"error": str(e)}), 500
2370-
finally:
2371-
db.close()

var/icad_dispatch.db-shm

-32 KB
Binary file not shown.

var/icad_dispatch.db-wal

Whitespace-only changes.

0 commit comments

Comments
 (0)