fix: patch_context() use try/finally to ensure unpatch on exception (#1743)

- Wrapped yield in try/finally block so unpatch_hub() executes even when
  the with-body raises an exception, preventing patch state leakage
This commit is contained in:
Xingjun.Wang
2026-06-25 16:04:11 +08:00
committed by GitHub
parent cf08fb242d
commit 39583ec639

View File

@@ -1014,5 +1014,7 @@ def unpatch_hub():
@contextlib.contextmanager
def patch_context():
patch_hub()
yield
unpatch_hub()
try:
yield
finally:
unpatch_hub()