Fix Orchestrator.__repr__ crash on partially-initialized instances#5073
Closed
gospartan wants to merge 1 commit into
Closed
Fix Orchestrator.__repr__ crash on partially-initialized instances#5073gospartan wants to merge 1 commit into
gospartan wants to merge 1 commit into
Conversation
Summary:
Fix `AttributeError` in `Orchestrator.__repr__()` when the object is only
partially initialized. The method checked `hasattr(self, "experiment")` but
did not check `hasattr(self, "generation_strategy")`, causing a crash when
`__repr__` was called between the two attribute assignments.
**Bug details:**
`Orchestrator.__init__` sets attributes in this order:
```
self.experiment = experiment # line 228
self._set_logger(options=options) # line 231
self.options = options # line 232
self.generation_strategy = generation_strategy # line 235
```
If any error occurs between lines 228-235 (e.g. in `_set_logger`), then
`self.experiment` exists but `self.generation_strategy` does not.
The `log_usage()` decorator on `OrcOpticsScheduler.__init__` catches such
errors and calls `repr(args)` to log them. Since `args[0]` is the partially-
initialized scheduler instance, this triggers `Orchestrator.__repr__()`:
```python
def __repr__(self) -> str:
if not hasattr(self, "experiment"): # True -- experiment IS set
return f"{self.__class__.__name__}"
return (
f"...generation_strategy={self.generation_strategy}..." # BOOM
)
```
The secondary `AttributeError` replaces the original error, making the real
failure impossible to diagnose.
**Example:** FBLearner run f1051747930 failed with:
```
AttributeError: 'OrcOpticsScheduler' object has no attribute 'generation_strategy'
```
Stack trace: `OrcOpticsScheduler.__init__` -> `Orchestrator.__init__` ->
(error between lines 228-235) -> `log_usage` error handler ->
`repr(args)` -> `Orchestrator.__repr__` -> `self.generation_strategy` crash.
The actual root cause was completely masked by this `__repr__` bug.
**Fix:** Add `hasattr(self, "generation_strategy")` guard alongside the
existing `hasattr(self, "experiment")` check.
Differential Revision: D97166104
|
@gospartan has exported this pull request. If you are a Meta employee, you can view the originating Diff in D97166104. |
|
This pull request has been merged in 5bff9c3. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fix
AttributeErrorinOrchestrator.__repr__()when the object is onlypartially initialized. The method checked
hasattr(self, "experiment")butdid not check
hasattr(self, "generation_strategy"), causing a crash when__repr__was called between the two attribute assignments.Bug details:
Orchestrator.__init__sets attributes in this order:If any error occurs between lines 228-235 (e.g. in
_set_logger), thenself.experimentexists butself.generation_strategydoes not.The
log_usage()decorator onOrcOpticsScheduler.__init__catches sucherrors and calls
repr(args)to log them. Sinceargs[0]is the partially-initialized scheduler instance, this triggers
Orchestrator.__repr__():The secondary
AttributeErrorreplaces the original error, making the realfailure impossible to diagnose.
Example: FBLearner run f1051747930 failed with:
Stack trace:
OrcOpticsScheduler.__init__->Orchestrator.__init__->(error between lines 228-235) ->
log_usageerror handler ->repr(args)->Orchestrator.__repr__->self.generation_strategycrash.The actual root cause was completely masked by this
__repr__bug.Fix: Add
hasattr(self, "generation_strategy")guard alongside theexisting
hasattr(self, "experiment")check.Differential Revision: D97166104