Python: Improve File Not Closed query to reduce false positives and provide clearer alerts#20392
Merged
joefarebrother merged 6 commits intogithub:mainfrom Sep 18, 2025
Conversation
This reduces some confusing FPs, though appears to introduce another
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the Python "File Not Closed" query to reduce false positives and enhance alert clarity. The changes focus on better handling of with statements that guard exceptions and providing more informative error messages by linking to specific exception-raising locations.
- Refactored exception guarding logic to use local dataflow instead of basic block reachability
- Enhanced alert messages to include links to specific operations that may raise exceptions
- Added comprehensive test cases documenting previous false positive behaviors
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/ql/src/Resources/FileNotAlwaysClosed.ql | Updated query to support enhanced alert messages with exception location links |
| python/ql/src/Resources/FileNotAlwaysClosedQuery.qll | Improved exception guarding logic and dataflow analysis for better accuracy |
| python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py | Updated test annotations and added new test cases for previous false positives |
| python/ql/test/query-tests/Resources/FileNotAlwaysClosed/FileNotAlwaysClosed.qlref | Added query reference configuration |
| python/ql/test/query-tests/Resources/FileNotAlwaysClosed/FileNotAlwaysClosed.expected | Added expected test results |
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py
Outdated
Show resolved
Hide resolved
python/ql/test/query-tests/Resources/FileNotAlwaysClosed/resources_test.py
Outdated
Show resolved
Hide resolved
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.
withstatements guarding exceptions, that was resulting in some unintuitve false positives