Skip to content

fix(runtime): restore EnvField overrides after exceptions#601

Draft
Xiangyi1996 wants to merge 1 commit into
mainfrom
fix/env-field-override-finally
Draft

fix(runtime): restore EnvField overrides after exceptions#601
Xiangyi1996 wants to merge 1 commit into
mainfrom
fix/env-field-override-finally

Conversation

@Xiangyi1996

Copy link
Copy Markdown
Collaborator

Summary

  • restore an EnvField override from a finally block
  • preserve both the original environment variable and the internal explicit-None state
  • add regression tests for exceptions raised while an override is active

Why

EnvField.override() previously restored its saved state only after the context manager body returned normally. If the body raised, execution skipped the restoration code and leaked the temporary environment value into later work.

This is particularly misleading in tests: one expected assertion failure can change backend configuration for subsequent tests and produce unrelated cascading failures. The same issue affects callers that use scoped runtime overrides.

Behavior

The normal-path behavior is unchanged. On both normal return and exception, the context manager now restores:

  • a previously present environment variable
  • a previously absent environment variable and its default fallback
  • the internal explicit-None marker

Validation

  • pre-commit run --all-files: passed
  • pytest -q test/runtime/test_env.py: 3 passed

This PR is independent of #600 and targets main directly.

Signed-off-by: Xiangyi Zhang <xiangyiz@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant