Skip to content

feat: enhance error logging and add error_handler to queries - #727

Merged
luisremis merged 15 commits into
developfrom
fix/issue-172
May 25, 2026
Merged

feat: enhance error logging and add error_handler to queries#727
luisremis merged 15 commits into
developfrom
fix/issue-172

Conversation

@ad-claw000

Copy link
Copy Markdown
Contributor

Summary

Enhances the logging mechanism for query errors to avoid unmanageable log sizes when large batches fail. Added an error_handler argument to execute_query, execute_batch_sets, and ParallelQuery generators to allow downstream handling of query errors natively for post-mortem analysis.

Verification

Ran the pytest test/test_Images.py successfully and executed test/test_Parallel.py.

Fixes #172.

Copilot AI review requested due to automatic review settings May 21, 2026 07:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_handler callback to CommonLibrary.execute_query and propagated it through ParallelQuery and ParallelQuerySet execution.
  • Reduced error/partial-error logging verbosity to avoid dumping full queries and large warning payloads.
  • Added explicit client deletion at the end of ParallelQuery.worker to 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.

Comment thread aperturedb/CommonLibrary.py
Comment thread aperturedb/ParallelQuery.py Outdated

@ad-claw000 ad-claw000 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All PR review comments have been addressed in the latest commit.

Copilot AI review requested due to automatic review settings May 21, 2026 15:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/CommonLibrary.py Outdated
Comment thread aperturedb/CommonLibrary.py Outdated
- 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
Copilot AI review requested due to automatic review settings May 21, 2026 16:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread test/test_ResponseHandler.py Outdated
Comment thread test/test_ResponseHandler.py Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 03:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 new error_handler.
        # Transaction failed entirely.
        logger.error(
            f"Failed query = {query} with response = {censor_tokens(r)}")
        result = 1

Comment thread aperturedb/CommonLibrary.py Outdated
Comment thread aperturedb/ParallelQuerySet.py Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 11:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread aperturedb/CommonLibrary.py Outdated
Comment thread aperturedb/ParallelQuerySet.py Outdated
luisremis
luisremis previously approved these changes May 24, 2026
Copilot AI review requested due to automatic review settings May 24, 2026 01:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_sets logs commands_per_query/blobs_per_query before the None-defaults are normalized (they’re set a few lines later), so the info log will often show None rather 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 on error_handler/returned response for full details.
        # Transaction failed entirely.
        logger.error(
            f"Failed query = {query} with response = {censor_tokens(r)}")
        result = 1

Comment thread aperturedb/ParallelQuerySet.py Outdated
- 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
Copilot AI review requested due to automatic review settings May 24, 2026 11:15
@ad-claw000

Copy link
Copy Markdown
Contributor Author

Addressed the low confidence review comments regarding logging in commit 45d0f95. Moved logging of commands_per_query and blobs_per_query down to correctly log defaults, and truncated the failed query in the total transaction failure error log to prevent unmanageably large logs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread aperturedb/CommonLibrary.py Outdated
Comment thread aperturedb/ParallelQuerySet.py Outdated
Comment thread aperturedb/ParallelQuerySet.py Outdated
@luisremis
luisremis merged commit 9a096a0 into develop May 25, 2026
3 checks passed
@luisremis
luisremis deleted the fix/issue-172 branch June 11, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The simple "log on error" approach to errors in connector query needs to be enahnced.

3 participants