Repository navigation
Commit e270d1e
Mohamed Zeidan
fix: forward __delattr__ on the lazy JumpStart session proxy
_LazyJumpStartSagemakerSession declares __slots__ = () and forwards
__getattr__/__setattr__ but not __delattr__. unittest.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, worse, leaves the mock installed on the process-wide session, so
unrelated tests in the same worker then see the mock instead of the real
attribute.
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 a28524a commit e270d1e
2 files changed
Lines changed: 55 additions & 0 deletions
File tree
- sagemaker-core
- src/sagemaker/core/jumpstart
- tests/unit/jumpstart
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
243 | 252 | | |
244 | 253 | | |
245 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 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 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
0 commit comments