Skip to content

Commit 280d881

Browse files
fix(aap): path fix for django view arguments (#14268)
fixing issue #14258 Also little change to the django app for threats tests to have a regression test. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Brett Langdon <[email protected]>
1 parent b74e3da commit 280d881

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

ddtrace/contrib/internal/django/patch.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@ def _instrument_view(django, view, path=None):
667667
def traced_urls_path(django, pin, wrapped, instance, args, kwargs):
668668
"""Wrapper for url path helpers to ensure all views registered as urls are traced."""
669669
try:
670-
from_args = False
671-
view = kwargs.pop("view", None)
672-
path = kwargs.pop("path", None)
673-
if view is None:
670+
view_from_args = False
671+
view = kwargs.get("view", None)
672+
path = kwargs.get("route", None)
673+
if view is None and len(args) > 1:
674674
view = args[1]
675-
from_args = True
676-
if path is None:
675+
view_from_args = True
676+
if path is None and args:
677677
path = args[0]
678678

679679
core.dispatch("service_entrypoint.patch", (unwrap(view),))
680-
if from_args:
680+
if view_from_args:
681681
args = list(args)
682682
args[1] = instrument_view(django, view, path=path)
683683
args = tuple(args)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
AAP: This fix resolves an issue where the ``route`` parameter was not being correctly handled in the Django path function.

tests/appsec/contrib_appsec/django_app/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def shutdown(request):
286286
path("new_service/<str:service_name>", new_service, name="new_service"),
287287
path("rasp/<str:endpoint>/", rasp, name="rasp"),
288288
path("rasp/<str:endpoint>", rasp, name="rasp"),
289-
path("login/", login_user, name="login"),
289+
path(route="login/", view=login_user, name="login"),
290290
path("login", login_user, name="login"),
291291
path("login_sdk/", login_user_sdk, name="login_sdk"),
292292
path("login_sdk", login_user_sdk, name="login_sdk"),

0 commit comments

Comments
 (0)