Commit c4412eb
Fix tracing-state leak after transform exceptions (#9019)
Fixes #7701.
### Description
`TraceableTransform.trace_transform()` now restores the previous tracing
state even when code inside the context manager raises. The original
exception still propagates unchanged.
The previous implementation restored `self.tracing` only after a normal
`yield`, so an exception permanently leaked the temporary tracing value
into the transform. This caused later inverse transforms to fail with
`Transform Tracing must be enabled` after a caught CUDA OOM or another
runtime exception.
### Types of changes
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.
### Validation
- The regression fails on `upstream/dev` because the tracing state
remains changed after an exception.
- `python -m pytest tests/transforms/inverse/test_traceable_transform.py
-q`: 2 passed.
- Black, isort, Ruff, mypy, documentation build, packaging, DCO, and
pre-commit checks pass in upstream CI.
- `git diff --check` passes.
Signed-off-by: kyinhub <kevinpyin@gmail.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent 21cbeda commit c4412eb
2 files changed
Lines changed: 24 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
406 | 413 | | |
407 | 414 | | |
408 | | - | |
409 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
410 | 419 | | |
411 | 420 | | |
412 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
32 | 44 | | |
33 | 45 | | |
34 | 46 | | |
| |||
0 commit comments