fix(agent): return message instead of raising ItemNotFoundError in get_lineage_paths_between#17014
Open
psaikaushik wants to merge 2 commits intodatahub-project:masterfrom
Open
Conversation
…ge_paths_between When no lineage path exists between two assets, get_lineage_paths_between was raising ItemNotFoundError. In an agent/ADK context this surfaces as an unhandled exception instead of a useful response. Now it returns a dict with a human-readable message, the source/target info, pathCount=0, and an empty paths array. This lets agents handle "no lineage found" as a normal outcome rather than an error. Also adds _build_no_path_found_message() helper for consistent formatting across both auto-discover and explicit direction code paths. Tests updated: test_path_not_found_raises_error replaced with test_path_not_found_returns_message that checks the message dict. Added test_path_not_found_auto_discover_returns_message for the auto-discover path. Closes datahub-project#16882
The import was left over after replacing test_path_not_found_raises_error (which used pytest.raises(ItemNotFoundError)) with test_path_not_found_returns_message (which checks the message dict). Ruff flags this as F401 (unused import).
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.
Summary
When no lineage path exists between two assets,
get_lineage_paths_betweenraisesItemNotFoundError. In an agent/ADK context this surfaces as an unhandled exception instead of a useful response.Closes #16882
What Changed
datahub-agent-context/src/datahub_agent_context/mcp_tools/lineage.pyget_lineage_paths_between()now catchesItemNotFoundErrorand returns a friendly message dict instead of raising_build_no_path_found_message()helper that returns a consistent response withmessage,source,target,pathCount=0, and emptypathsItemNotFoundErrorfrom theRaisessection of the docstringdatahub-agent-context/tests/unit/mcp_tools/test_lineage.pytest_path_not_found_raises_error(which expectedItemNotFoundError) withtest_path_not_found_returns_messagethat checks the message dicttest_path_not_found_auto_discover_returns_messagefor the auto-discover code pathBefore vs After
Before (raises, agent sees unhandled error):
After (returns dict, agent gets a usable response):
{ "message": "No lineage path found between urn:li:dataset:A and urn:li:dataset:B in either upstream or downstream direction.", "source": {"urn": "urn:li:dataset:A"}, "target": {"urn": "urn:li:dataset:B"}, "pathCount": 0, "paths": [] }Notes
_find_upstream_lineage_path,_find_lineage_path) still raiseItemNotFoundErrorfor control flow. Only the public-facingget_lineage_paths_betweencatches and converts them.get_lineage()which has different behavior and is not affected by this issue.