fix(analyzers): handle empty ASN history in BGPRanking#3733
Open
Valyrian-Code wants to merge 1 commit into
Open
fix(analyzers): handle empty ASN history in BGPRanking#3733Valyrian-Code wants to merge 1 commit into
Valyrian-Code wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Prevents BGPRanking.run() from crashing when the BGP Ranking API returns an empty ASN history, and adds a regression unit test for the scenario.
Changes:
- Add guard logic in
BGPRanking.run()to handle empty"response"withoutpopitem()raisingKeyError. - Add a unit test asserting a clean
AnalyzerRunExceptionis raised for empty ASN history.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/api_app/analyzers_manager/unit_tests/observable_analyzers/test_bgp_ranking.py | Adds a regression test for empty ASN history behavior. |
| api_app/analyzers_manager/observable_analyzers/bgp_ranking.py | Adds a defensive check to avoid popitem() on an empty dict and raise AnalyzerRunException instead. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When BGP Ranking has no ASN history for an IP, the API returns an empty "response" object. Calling .popitem() on that empty dict raised an uncaught "KeyError: 'popitem(): dictionary is empty'" before the intended "ASN not found" AnalyzerRunException could be raised. Guard the empty case so the analyzer reports a clean AnalyzerRunException instead of crashing with a traceback. Behaviour is unchanged when ASN history is present. Adds a regression test covering the empty response.
a6bf663 to
81008c1
Compare
Author
|
Hi @mlodic,
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
When BGP Ranking has no ASN history for an IP, the API returns an empty
responseobject. The current implementation calls.popitem()on that empty dictionary, resulting in an uncaught:This occurs before the intended
AnalyzerRunException("ASN not found ...")can be raised.This change handles the empty-response case explicitly, allowing the analyzer to raise a clean
AnalyzerRunExceptioninstead of terminating with a traceback. Behavior remains unchanged when ASN history is available.Type of Change
Tests
Added a regression test,
test_run_raises_clean_exception_on_empty_asn_history, which mocks an empty API response:{"response": {}}The test verifies that
AnalyzerRunExceptionis raised.Fails on the current code with:
Passes with this fix applied.
All existing tests continue to pass.
ruff checkandruff format --checkare also clean.