Skip to content

Add Route nodes and HANDLES edges for DRF ViewSet actions#647

Closed
muskiteer wants to merge 2 commits into
DeusData:mainfrom
muskiteer:fix/drf-route-handlers
Closed

Add Route nodes and HANDLES edges for DRF ViewSet actions#647
muskiteer wants to merge 2 commits into
DeusData:mainfrom
muskiteer:fix/drf-route-handlers

Conversation

@muskiteer

@muskiteer muskiteer commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR adds support for indexing Django REST Framework ViewSet actions decorated with @action by emitting Route nodes and Route-[:HANDLES]->Method relationships.

Previously, DRF action methods were indexed only as Method nodes, which meant endpoint inventory and endpoint-to-handler mapping were incomplete for projects using DRF routers.

Changes

  • Emit Route nodes for DRF @action methods.
  • Populate route metadata (HTTP method, path, source, and file path where available).
  • Create Route-[:HANDLES]->Method relationships linking routes to their corresponding handler methods.
  • Preserve existing Method extraction.

Verification

Reproduced using a minimal Django REST Framework project:

class CustomerTaskAdminViewSet(ViewSet):
    @action(detail=True, methods=["post"])
    def approve_draft_with_charge(self, request, pk=None):
        ...

Before:

  • Method node was present.
  • No Route nodes were emitted.
  • No Route-[:HANDLES]->Method relationships existed.

After:

  • Route node is emitted.
  • Route-[:HANDLES]->Method relationship is created.
  • Route metadata is available for the action.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

Fixes #603

Signed-off-by: muskiteer <agarwal.vansh3110@gmail.com>
@muskiteer

Copy link
Copy Markdown
Contributor Author

Hi @DeusData,
I've opened a PR for the DRF ViewSet route extraction changes.

While testing locally, I ran into some issues with the test and lint targets. From what I could tell, these didn't appear to be directly related to the changes in this PR, but please let me know if I missed something.

I'd really appreciate any feedback or suggested changes. Happy to update the PR if needed.

Thanks

Signed-off-by: muskiteer <agarwal.vansh3110@gmail.com>
@DeusData

Copy link
Copy Markdown
Owner

Huge thanks for opening this PR and for the work you put into it.

The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime.

@muskiteer

Copy link
Copy Markdown
Contributor Author

@DeusData Thanks for the msg.
I am actually still working on this so take your time
Thanks

@DeusData DeusData added bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/normal Standard review queue; useful PR with ordinary maintainer urgency. labels Jun 29, 2026
@DeusData

DeusData commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Thank you @muskiteer — the DRF ViewSet @action extractor is genuinely useful work, and #603 was a real, previously-unhandled gap (no @action handling existed on main). I've verified the extractor logic is sound and the reproduce-first test is a valid guard.

I'm landing it as a focused distillation in #746 (024c0c5), co-authored with you, rather than merging this PR directly. The reason: alongside the extractor, this PR also reverses the HANDLES edge direction project-wide (handler→RouteRoute→handler) across every framework (FastAPI/Flask/Express/Gin/gRPC/SvelteKit/…). That change is:

  • Not needed for the fix — the added test counts HANDLES by type (direction-agnostic), and the existing Phase 2a pipeline already emits the edge, so the extractor alone closes Django REST Framework ViewSet routes miss HANDLES mappings #603 and greens the test; and
  • A latent regressionpass_cross_repo.c's find_route_handler resolves a route's handler via WHERE e.target_id = <route> AND e.type='HANDLES' (i.e. it relies on handler→Route) and isn't updated in this PR, so after the flip, cross-repo route→handler resolution would silently return 0. No test catches it because the edge-count checks are direction-agnostic.

So the distilled PR keeps your extractor, drops the direction flip, preserves the documented handler→Route convention, and adds your test as the reproduce-first guard. Full credit to you as co-author. If the team ever wants Route→handler as the canonical direction, that's a deliberate, separate change that must update every consumer (pass_cross_repo.c, the schema, and the docs) together.

Really appreciate the contribution — the DRF support ships in the next release. 🙏

@DeusData DeusData closed this Jul 1, 2026
pull Bot pushed a commit to sorajate/codebase-memory-mcp that referenced this pull request Jul 1, 2026
…thods

Django REST Framework ViewSets expose extra endpoints through @action-decorated
methods, e.g. @action(detail=True, methods=["post"], url_path="approve"). On
main these methods carried no route_path, so Phase 2a created no Route node and
no HANDLES edge for them -- the endpoint was invisible in the graph (DeusData#603).

Add try_drf_action_decorator (internal/cbm/extract_defs.c): when a method's
decorator identifier is "action", read the methods / url_path / detail kwargs
and set *out_path/*out_method. The existing decorator-route pipeline
(ensure_one_decorator_route, Phase 2a) then creates the Route + handler->Route
HANDLES edge in the established direction. Fallbacks: method name for url_path,
"GET" for methods; detail=True -> /{pk}/<seg>, else /<seg>.

Reproduce-first guard: handles_drf_action_python in the edge_types_probe suite
-- a DRF @action method must produce >=1 HANDLES edge (RED with 0 edges before
the extractor, GREEN after).

Known limitation: multi-method actions (methods=["get","post"]) capture only the
first method -> a single Route.

Distilled from DeusData#647 (thanks @muskiteer). Drops that PR's unrelated project-wide
HANDLES edge-direction reversal, which was unnecessary for the fix and broke the
handler->Route convention relied on by pass_cross_repo.c's find_route_handler.

Closes DeusData#603

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Co-Authored-By: muskiteer <agarwal.vansh3110@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/normal Standard review queue; useful PR with ordinary maintainer urgency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django REST Framework ViewSet routes miss HANDLES mappings

2 participants