[Repo Assist] fix: replace bare except clauses with specific NetworkX exceptions#1421
Open
github-actions[bot] wants to merge 1 commit intomainfrom
Open
Conversation
- graph_operations.py:244: catch nx.NetworkXNoPath instead of bare except, consistent with the same pattern in networkx_plotting.py - id_identifier.py:128: catch nx.NetworkXUnfeasible instead of bare except, which is the exception nx.topological_sort() raises for graphs containing cycles Bare except clauses mask unrelated bugs (e.g. MemoryError, KeyboardInterrupt) and make debugging harder. Both replacements preserve existing behaviour exactly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
8 tasks
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.
🤖 This is an automated pull request from Repo Assist.
Summary
Two bare
except:clauses in the dowhy codebase were masking all exceptions — includingMemoryError,KeyboardInterrupt, and genuine programming bugs. This PR replaces them with the precise NetworkX exceptions that are actually expected.Changes
dowhy/utils/graph_operations.py(line 244)Before:
After:
networkx.algorithms.shortest_paths.generic.shortest_pathraisesnx.NetworkXNoPathwhen no path exists betweenpaandi. This is the only expected "not found" scenario here. This fix is consistent with the identical pattern already used indowhy/utils/networkx_plotting.py.dowhy/causal_identifier/id_identifier.py(line 128)Before:
After:
nx.topological_sort()raisesnx.NetworkXUnfeasiblewhen the graph contains a cycle (i.e., is not a DAG). That is precisely the condition the error message describes.Rationale
Bare
except:clauses:KeyboardInterruptandSystemExit, making it impossible to interrupt the programNameErrorinsideshortest_pathwould be silently ignored)E722) and considered an anti-pattern in PythonBoth replacements are behaviour-preserving — the original intent is captured precisely by the specific exception types.
Test Status
graph_operations.pymirrors the existingexcept nx.NetworkXNoPath:pattern already used innetworkx_plotting.py. Tests will run via CI.Note
🔒 Integrity filtering filtered 38 items
Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.
list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)