Skip to content

Commit 0334372

Browse files
fix(asm): do not imply the callback is registered (#8074)
Following #8057 allowing less import if appsec is not loaded, wsgi_environ may not be registered. But the wrapper was making the assumption it was always registered. This PR fixes that. No changelog needed as it's fixing an unreleased bug. Note: Bug was detected on python3.12 weblog on system-tests ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] 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) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that.
1 parent 7dbb2cc commit 0334372

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ddtrace/contrib/django/patch.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ddtrace.internal.constants import COMPONENT
2828
from ddtrace.internal.constants import HTTP_REQUEST_BLOCKED
2929
from ddtrace.internal.constants import STATUS_403_TYPE_AUTO
30+
from ddtrace.internal.core.event_hub import ResultType
3031
from ddtrace.internal.logger import get_logger
3132
from ddtrace.internal.schema import schematize_service_name
3233
from ddtrace.internal.schema import schematize_url_operation
@@ -822,7 +823,16 @@ def _(m):
822823

823824

824825
def wrap_wsgi_environ(wrapped, _instance, args, kwargs):
825-
return core.dispatch_with_results("django.wsgi_environ", (wrapped, _instance, args, kwargs)).wrapped_result.value
826+
result = core.dispatch_with_results("django.wsgi_environ", (wrapped, _instance, args, kwargs)).wrapped_result
827+
# if the callback is registered and runs, return the result
828+
if result:
829+
return result.value
830+
# if the callback is not registered, return the original result
831+
elif result.response_type == ResultType.RESULT_UNDEFINED:
832+
return wrapped(*args, **kwargs)
833+
# if an exception occurs, raise it. It should never happen.
834+
elif result.exception:
835+
raise result.exception
826836

827837

828838
def patch():

0 commit comments

Comments
 (0)