feat(extract): Route+HANDLES for Django REST Framework @action methods#746
Merged
Conversation
…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 (#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 #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 #603 Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com> Co-Authored-By: muskiteer <agarwal.vansh3110@gmail.com>
4 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.
Distilled from #647 (thanks @muskiteer for the DRF ViewSet extractor).
What
Django REST Framework ViewSets expose extra endpoints through
@action-decorated methods:On
mainthese methods carried noroute_path, so Phase 2a created noRoutenode and noHANDLESedge for them — the endpoint was invisible in the graph (#603).Fix
try_drf_action_decorator(internal/cbm/extract_defs.c): when a method's decorator identifier isaction, read themethods/url_path/detailkwargs and set*out_path/*out_method. The existing decorator-route pipeline (ensure_one_decorator_route, Phase 2a) then creates theRoute+handler→RouteHANDLESedge in the established direction. Fallbacks: method name forurl_path,"GET"formethods;detail=True→/{pk}/<seg>, else/<seg>.Reproduce-first
handles_drf_action_python(edge_types_probesuite): a DRF@actionmethod must produce ≥1HANDLESedge. RED (0 edges) onmainwithout the extractor, GREEN with it. Full suite green.Scope note (why a distillation, not a merge of #647)
#647 bundled this extractor with an unrelated project-wide reversal of the
HANDLESedge direction (handler→Route→Route→handler) across every framework. That reversal was (a) unnecessary — the test countsHANDLESdirection-agnostically and the extractor alone closes #603 — and (b) a latent regression:pass_cross_repo.c'sfind_route_handlerresolves a route's handler withWHERE e.target_id = <route> AND e.type='HANDLES'(assumeshandler→Route) and was not updated, so cross-repo route→handler resolution would silently return 0. This PR keeps only the extractor and preserves the documented convention.Known limitation
Multi-method actions (
methods=["get","post"]) capture only the first method → a singleRoute. Left as a follow-up.Closes #603
Co-authored with @muskiteer.