Skip to content

Fix Elastic adapter when attempting to generate notes for non-ApiError exceptions#230

Open
JSCU-CNI wants to merge 1 commit into
fox-it:mainfrom
JSCU-CNI:elastic-notes
Open

Fix Elastic adapter when attempting to generate notes for non-ApiError exceptions#230
JSCU-CNI wants to merge 1 commit into
fox-it:mainfrom
JSCU-CNI:elastic-notes

Conversation

@JSCU-CNI

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.27%. Comparing base (e6b58fd) to head (2bc9913).

Files with missing lines Patch % Lines
flow/record/adapter/elastic.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #230      +/-   ##
==========================================
- Coverage   84.29%   84.27%   -0.02%     
==========================================
  Files          35       35              
  Lines        3756     3758       +2     
==========================================
+ Hits         3166     3167       +1     
- Misses        590      591       +1     
Flag Coverage Δ
unittests 84.27% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yunzheng yunzheng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm it looks like create_elasticsearch_error_notes only considered BulkIndexError, where .errors is a list of Dicts:

https://github.com/elastic/elasticsearch-py/blob/6df97e3c21adffeb33d0a4c64dc784e618d85f41/elasticsearch/helpers/errors.py#L21

And it seems TransportError also has .errors but is a tuple of Exception:

https://github.com/elastic/elastic-transport-python/blob/08a5d72e93d6306579b732ef5e2e5a4948134898/elastic_transport/_exceptions.py#L31

Comment on lines +286 to +289
# The stack of errors could include different exceptions, such as TransportErrors.
if not hasattr(error, "get"):
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm it looks like create_elasticsearch_error_notes only considered BulkIndexError, where .errors is a list of Dicts:

https://github.com/elastic/elasticsearch-py/blob/6df97e3c21adffeb33d0a4c64dc784e618d85f41/elasticsearch/helpers/errors.py#L21

And it seems TransportError also has .errors but is a tuple of Exception:

https://github.com/elastic/elastic-transport-python/blob/08a5d72e93d6306579b732ef5e2e5a4948134898/elastic_transport/_exceptions.py#L31

I think instead of skipping we should consider it being a dictionary or an Exception (and update the typing), then in the loop we can still add the error as a note:

    notes = []
    for idx, error in enumerate(errors, 1):
        if isinstance(error, Exception):
            # Create formatted Exception note
            note_parts = [
                f"Error {idx}, {error}",
            ]
        elif isinstance(error, dict):
            # Extract index information
            ....
        notes.append("\n".join(note_parts) + "\n")

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.

2 participants