Skip to content

Commit c789aaa

Browse files
authored
fix: keep the sre_constants module [backport #6255 to 1.14] (#6323)
Backport of #6255 to 1.14 The re module imports from the sre_constants module at runtime. This might cause issues when modules are unloaded in the sitecustomize. Fixes #6197. ## 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)
1 parent 84d8893 commit c789aaa

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

ddtrace/bootstrap/sitecustomize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def drop(module_name):
109109
"concurrent",
110110
"typing",
111111
"re", # referenced by the typing module
112+
"sre_constants", # imported by re at runtime
112113
"logging",
113114
"attr",
114115
"google.protobuf", # the upb backend in >= 4.21 does not like being unloaded
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug that caused applications using gevent and cassandra to fail to
5+
start with the ddtrace-run command.

tests/commands/test_runner.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,16 @@ def test_no_args():
468468
p.wait()
469469
assert p.returncode == 1
470470
assert six.b("usage:") in p.stdout.read()
471+
472+
473+
@pytest.mark.subprocess(ddtrace_run=True, env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="1"))
474+
def test_ddtrace_re_module():
475+
import re
476+
477+
re.Scanner(
478+
(
479+
("frozen", None),
480+
(r"[a-zA-Z0-9_]+", lambda s, t: t),
481+
(r"[\s,<>]", None),
482+
)
483+
)

0 commit comments

Comments
 (0)