You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(iast): add code to filter out ddtrace stuff from dir() on patched modules [backport 2.17] (#11504)
Backport a9a6ad7 from #11490 to 2.17.
Signed-off-by: Juanjo Alvarez <[email protected]>
## Description
While testing on dd-source CI we found an issue where a module was doing
a `dir(other_module)` and the changed results from the patched module
were breaking stuff (because our patching would add `ddtrace_aspects`,
`ddtrace_sink_points`, et cetera to the results and the original module
was expecting all `other_module` symbols to have some members like
`id`).
This PRs fixes this problem by:
- Creating a custom `__dir__` function (that will override any
pre-existing ones) removing from the results all the symbols that we add
ourselves while patching.
- Renaming all added `ddtrace` symbols to `__ddtrace`.
Also:
- Adds a `_DD_IAST_NO_DIR_PATCH` config var to disable the wrapping of
the patched module `__dir__` functions in case the user have some
side-effect problem.
- The return type of `visit_ast` has been fixed (it wrongly was `str`
while is in fact a `ast.Module` type).
## 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: Juanjo Alvarez Martinez <[email protected]>
0 commit comments