feat: enhance error logging and add error_handler to queries - #727
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances error handling in the ApertureDB Python SDK’s batch/parallel query execution path by reducing overly verbose error logs for large failed batches and introducing an error_handler callback to let downstream code capture failed/partial-failure details for post-mortem analysis.
Changes:
- Added an optional
error_handlercallback toCommonLibrary.execute_queryand propagated it throughParallelQueryandParallelQuerySetexecution. - Reduced error/partial-error logging verbosity to avoid dumping full queries and large warning payloads.
- Added explicit client deletion at the end of
ParallelQuery.workerto attempt earlier connection cleanup.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| aperturedb/CommonLibrary.py | Adds error_handler support and trims verbose error logging in execute_query. |
| aperturedb/ParallelQuery.py | Plumbs generator-provided error_handler into batch execution; adds client cleanup logic in worker threads. |
| aperturedb/ParallelQuerySet.py | Extends batch-set execution wrapper to accept/pass through error_handler. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ad-claw000
left a comment
There was a problem hiding this comment.
All PR review comments have been addressed in the latest commit.
- Switched from BaseException to Exception in response/error handlers - Re-raised using bare raise to preserve traceback context - Added monkeypatch tests for error_handler scenarios
- restore 'with open' in Sources.py and VideoDataCSV.py to fix UnboundLocalError - restore 'with iolock' in cli/mount_coco.py to avoid deadlock on exception - revert broken DaskManager.py changes which removed 'raise' causing UnboundLocalError - restore dry_run kwarg pass in ParallelQuery.py for DaskManager
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
aperturedb/CommonLibrary.py:324
- The total-transaction-failure log still interpolates the full
query(and full response) into the ERROR message. For large batches this can still generate extremely large log lines, which undermines the stated goal of keeping logs manageable. Consider logging a bounded summary instead (e.g., number of commands, top-level status/info, and optionally a truncated/capped preview), and keep full query/response only behind DEBUG or via the newerror_handler.
# Transaction failed entirely.
logger.error(
f"Failed query = {query} with response = {censor_tokens(r)}")
result = 1
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
aperturedb/ParallelQuerySet.py:60
execute_batch_setslogscommands_per_query/blobs_per_querybefore the None-defaults are normalized (they’re set a few lines later), so the info log will often showNonerather than the effective values. Consider moving this log statement after the defaults are filled in (or log both the raw input and the computed defaults) to keep the log actionable.
logger.info("Execute Batch Sets = Batch Size {0} Comands Per Query {1} Blobs Per Query {2}".format(
len(query_set), commands_per_query, blobs_per_query))
aperturedb/CommonLibrary.py:324
- The total-transaction-failure path still logs the entire
query(and full response) at error level. For large batches this can still produce unmanageably large logs, which seems to conflict with the PR goal of limiting error log size. Consider logging a summarized/truncated representation (e.g., number of commands and the first N commands) and rely onerror_handler/returned response for full details.
# Transaction failed entirely.
logger.error(
f"Failed query = {query} with response = {censor_tokens(r)}")
result = 1
- Move logging of commands_per_query and blobs_per_query down so they don't log None - Truncate the failed query in the total transaction failure error log
|
Addressed the low confidence review comments regarding logging in commit 45d0f95. Moved logging of |
Summary
Enhances the logging mechanism for query errors to avoid unmanageable log sizes when large batches fail. Added an
error_handlerargument toexecute_query,execute_batch_sets, andParallelQuerygenerators to allow downstream handling of query errors natively for post-mortem analysis.Verification
Ran the
pytest test/test_Images.pysuccessfully and executedtest/test_Parallel.py.Fixes #172.