← Back to Pull requests

feat(code-facts): Django urlconfs, DRF routers and Flask mounts in the route matrix #412

Closed
unknown closed this pull request without merging on Nov 10, 2026 20:17 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 06:02 UTC
Author

First half of route ownership plan step 4 for Python (plans/route-ownership-matrix-plan.md, owner Michele; decisions D36–D38). This is the route matrix the Django, DRF and Flask ownership readers will build on. The readers come next, one PR per family, judge-only (D35).

Problem

Django rows came from a regex over files with "url" in their name:

  • one row per path() line, with method any;

  • no include() prefixes;

  • include(...) lines read as routes;

  • DRF routers unseen.
  • Guards were any name matching a guard-shaped regex, looked up by bare name across the checkout. So csrf_exempt, require_POST, SSLRequiredMixin, a decorator's string argument or a module name (permissions.ReadOnly) all read as guards. A commented-out setting did too, and one project's settings guarded another project's routes.

    Flask rows carried no mount prefix. Hooks, view classes and functions were keyed by bare name.

    What

    providers.django_routes (new) reads each project's urlconfs with ast, from its root:

  • urlpatterns as built: assignments, +=, .append/.extend, conditional additions, reduce(add, ..), format_suffix_patterns, i18n_patterns, lists imported from another module, and the checkout's own path() helpers.

  • include() chains: of modules, names, lists, router.urls and router.get_urls(), joined to their prefixes.

  • DRF routers, bound anywhere and registered from any module:

  • - list, detail, @action and .mapping rows;
    - helper-registered viewsets and registry.extend;
    - DefaultRouter's root view, trailing_slash, and nested routers' parent lookups.
  • Views:

  • - class views in C3 order, one row per method they or a library generic answer, with post = get aliases;
    - viewset mappings and re-exported definitions;
    - function views take their verbs from require_/api_view.
  • Settings: read as code, per project (ROOT_URLCONF), unconditional values only. A setting changed after it is set, or set in a try/if star import, is unknown. Only values every settings module of the project agrees on count.
  • Flask (route_guards):

  • prefixes for blueprints, flask-restful Api and flask-restx Namespace/api.namespace, keyed by the module each receiver is bound in, through imports and aliases;

  • blueprint and app subclasses, APIFlask, factory-made blueprints and apps handed to helpers;

  • app.route(rule)(fn), add_url_rule with @app.endpoint, wrapped as_view, methods= constants;

  • every Python file is parsed once and shared with the other Python families.
  • Guards (D37, providers.python_guards, new): a guard counts only when it is a known auth-library guard and no checkout definition shadows its name. Names read through their imports: an alias reads as the name it imports, and a known name imported from a library that isn't an auth library is no guard:

  • Django/DRF: login_required, LoginRequiredMixin, IsAuthenticated, …

  • Flask: flask-login, flask-jwt-extended, flask-httpauth, flask-security and the like.
  • Checkout decorators, mixins, permission classes and before_request hooks are never guards: their routes read judged. Among the known guards:

  • Permissions: read per method (AllowAny, …OrReadOnly, |/&/~). permission_classes counts only below @api_view. Overrides (get_permissions, initial, permission_denied, a skipping dispatch, as_view(), rebinding outside the class) leave permissions unknown.

  • Mixins: count only ahead of the library view whose dispatch runs first, and not when a checkout class overrides their hooks or dispatches past them.

  • LoginRequiredMiddleware: guards only checkout Django views. DRF views, login_not_required, view.login_required = False and Django's own auth views are exempt.

  • Flask:

  • - decorators count only below the route and inside any response cache;
    - optional=True/jwt_required(True) and LOGIN_DISABLED unguard;
    - OPTIONS gets its own unguarded row;
    - method_decorators counts only on flask-restful/restx Resource.
  • Unplaceable routes are listed with pattern_dynamic, never dropped: library urlconfs and routers, computed includes and prefixes, static(), library viewset actions and blueprints, Flask-Admin, error handlers. A connexion app is a coverage gap.
  • Behaviour changes

  • Django rows carry methods (not any) and their full mounted pattern.

  • Far fewer rows read guarded. Only known library guards count, so apps with their own auth decorators or permission classes now read judged, by decision D37. On one public sample app that uses its own permission class, 1,512 of 1,534 rows are judged.

  • csrf_, require_* method decorators, string arguments and module names are no longer guards.

  • DRF defaults apply only to DRF views.

  • before_request hooks no longer guard.

  • Python files named like tests are listed with test_path set, not dropped (a file like ab_test.py may serve routes). A test module's definitions and LOGIN_DISABLED count only inside that module.
  • Parity

    On a public sample of Django apps compared with development:

  • every handler development lists is still listed;

  • the new walk lists 1.0–215× as many distinct handlers;

  • every handler that loses its guard does so for one of the behaviour changes above.
  • On the Flask apps, rows gain their prefixes and none are lost. On a large monorepo the Django enumeration takes about 7 s.

    Review

    Three Qodo rounds are addressed in the last three commits, each fix with a regression test that fails before it. Four independent blind reviews found 56, 46, 28 and 38 holes as the guard rules narrowed (D36, D37). All are fixed. Per D38 there is no fifth round: guard reading is a reviewer aid, and each round finds new corners of library behaviour and Python name binding. All 168 review apps are kept as tests/fixtures/code_facts/django_flask_matrix_review.json, each with the rows it must list.

    Known limits

  • A Flask ANY row (unknown methods, dispatch_request) still shows its auth decorator, though OPTIONS may pass it. Every Flask auth guard is treated as OPTIONS-exempt.

  • Library-built Flask routes are found only from register_blueprint(<library call>) and Flask-Admin. Other extensions that add routes on init (flasgger, Flask-Security's blueprint) get no row.

  • Name binding ignores with … as, walrus, globals(), __getattr__ and setattr. A library star import is taken to bind nothing.

  • method_decorator(cache_page, name="dispatch") on a DRF class is not read.

  • An empty requirement is detected only from a literal.

  • LOGIN_DISABLED is checkout-wide: one setting outside tests turns flask-login's guards off, as does a value computed at run time. Comments and literal false don't. Environment variables set outside the checkout aren't seen.

  • A route registered on a helper's parameter is listed with pattern_dynamic unless the checkout calls that helper by name. pytest's tests and fixtures count as called; a helper only passed around as a value does not.

  • LOGIN_DISABLED takes the last assignment in each statement list, plus any a later if/try block may make.

  • Settings built by functions or environment lookups are unknown.

  • A checkout module that re-exports another library's decorator under a known guard's name (from oauth.utils import login_required in app/auth.py) still reads as a guard where it is imported.

  • A test module (named like a test, in a tests directory, or a conftest) shadows a guard and sets LOGIN_DISABLED only for itself.

  • The nested-router default lookup name is taken as nested_<n> and its pattern is marked dynamic.
  • Tests

    Changed tests (each approved by the owner):

    | Test | Old | New | Why |
    |---|---|---|---|
    | test_flask_methodview_one_row_per_method | guards from an unwritten checkout token_required | the library jwt_required(), assertion ["jwt_required"] | D37: checkout decorators are no guards |
    | test_flask_restx_method_decorators_and_inheritance | require_auth/require_scope from an unwritten module; family gap scope | flask_login.login_required, flask_security.roles_required; family gap role | D37; the family comes from the guard's name |
    | test_flask_restful_method_decorators_dict | admin_required from an unwritten module | roles_required('admin') | D37 |
    | test_flask_blueprint_before_request_is_baseline | the hook is a scope guard, row not judged | no scope guard, judged | D37: hooks are no guards |
    | test_flask_app_hook_scoped_to_its_app_and_registered_blueprints | both hooked routes show before_request:check_token | no scope guard, judged; the other app's route still judged | D37 |

    New tests:

  • test_django_routes.py: include chains, class-view methods, routers, settings per project, permission semantics, policy decorators, unplaceable routes, the D37/D38 cases, and the review fixture.

  • test_python_guards.py: the allowlist, shadowing, LOGIN_DISABLED and empty requirements.

  • In test_route_guards.py: Flask prefixes, receivers mounted two ways, decorator order, guards read through imports, methods never lending decorators, test-suite login switches, and the OPTIONS row.
  • Smoke test: the built wheel, installed into a fresh environment, enumerates public Django and Flask apps (179, 234 and 1,534 rows).

    Verification

  • Unit: 13,020 passed (after merging development).

  • Lint and format clean.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gurnben Review duration: 855m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #412"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%