Skip to content

Python: Support Flask subclasses#21869

Open
yoff wants to merge 4 commits into
github:mainfrom
yoff:python/support-flask-subclasses
Open

Python: Support Flask subclasses#21869
yoff wants to merge 4 commits into
github:mainfrom
yoff:python/support-flask-subclasses

Conversation

@yoff
Copy link
Copy Markdown
Contributor

@yoff yoff commented May 19, 2026

The pattern

result = API::moduleImport("flask").getMember("Flask") or
result = ModelOutput::getATypeNode("flask.Flask~Subclass").getASubclass*()

already returns all the subclasses for which we have MaD models, so we may as well replace it with

result = API::moduleImport("flask").getMember("Flask").getASubclass*() or
result = ModelOutput::getATypeNode("flask.Flask~Subclass").getASubclass*()

The predicate has been renamed from classRef to subclassRef with a deprecated alias.

This solves #21854

@@ -0,0 +1,8 @@
import python
import semmle.python.frameworks.Flask
import semmle.python.ApiGraphs
@yoff yoff force-pushed the python/support-flask-subclasses branch from 7cd7958 to 575ece6 Compare June 2, 2026 11:50
@yoff
Copy link
Copy Markdown
Contributor Author

yoff commented Jun 2, 2026

DCA showed a few new results which look fine.

@yoff yoff marked this pull request as ready for review June 2, 2026 12:08
@yoff yoff requested a review from a team as a code owner June 2, 2026 12:08
Copilot AI review requested due to automatic review settings June 2, 2026 12:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the Python Flask framework models so FlaskApp::instance() also matches instances of user-defined Flask subclasses, aligning the library behavior with real-world Flask usage (fixing #21854) and adding/adjusting tests and documentation to cover the new behavior.

Changes:

  • Extend the Flask app class reference to include subclasses and rename classRefsubclassRef (with a deprecated alias).
  • Add an inline-instance meta test helper and corresponding Flask library-tests (including a new Flask-subclass test case).
  • Update Flask library-test fixtures to tag Flask app instantiations as # $ instance, and add a change note.
Show a summary per file
File Description
python/ql/lib/semmle/python/frameworks/Flask.qll Adjusts Flask app class reference/instance modeling to include subclasses; introduces subclassRef and deprecates classRef.
python/ql/src/meta/ClassHierarchy/Find.ql Updates class hierarchy spec to use the new subclassRef predicate name.
python/ql/test/experimental/meta/InlineInstanceTest.qll Adds a reusable inline-expectations test helper for “instance” nodes.
python/ql/test/library-tests/frameworks/flask/InlineInstanceTest.ql Adds a test driver query for validating Flask app instance detection via inline expectations.
python/ql/test/library-tests/frameworks/flask/InlineInstanceTest.expected Adds expected output placeholder for the new inline instance test.
python/ql/test/library-tests/frameworks/flask/flask_subclass.py Adds a minimal Flask subclass example to validate subclass instance tracking.
python/ql/test/library-tests/frameworks/flask/*.py (template_test.py, taint_test.py, save_uploaded_file.py, routing_test.py, response_test.py, old_test.py) Adds # $ instance tags to existing Flask app instantiations for the new inline instance test coverage.
python/ql/lib/change-notes/2026-05-19-flask-subclasses.md Documents the behavioral change and API rename/deprecation.

Copilot's findings

  • Files reviewed: 12/13 changed files
  • Comments generated: 2

---
category: minorAnalysis
---
* `Flask::instance` will now also return instances of subclasses defined in te source tree. Previously, these were filtered out. `Flask::classRef` has been deprecated in favor of `Flask::subclassRef` since it already returned some subclasses. No newline at end of file
@@ -0,0 +1,29 @@
/**
* Defines a InlineExpectationsTest for class instances, that is,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants