Repository navigation
Commit 04b9546
Mohamed Zeidan
fix: forward __delattr__ on the lazy JumpStart session proxy
_LazyJumpStartSagemakerSession declares __slots__ = () and forwards
__getattr__/__setattr__ but not __delattr__. mock.patch reads the
original via target.__dict__[name], which the proxy forwards to the real
session's instance __dict__; for a class-level attribute such as
Session.read_s3_file that raises KeyError, so mock records
is_local=False and restores the attribute by calling delattr on teardown.
Without __delattr__ that teardown raises
AttributeError: '_LazyJumpStartSagemakerSession' object has no attribute ...
and leaves the mock installed on the process-wide session, so unrelated
tests in the same xdist worker then see the mock instead of the real
attribute. That is what made test_notebook_utils, test_model,
test_sagemaker_config and test_js_builder fail on py39-py312.
Forwarding __delattr__ removes the shadowing instance attribute created
by patch's setattr, which makes the class-level attribute visible again.
__slots__ is kept: dropping it does not fix this, because target.__dict__
would then resolve to the proxy's own empty dict and mock would still take
the delattr branch.
Adds two regression tests covering the class-level path (the defect) and
the instance-level path (is_local=True, restored via setattr).1 parent 9be072b commit 04b9546
2 files changed
Lines changed: 56 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
239 | 249 | | |
240 | 250 | | |
241 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
0 commit comments