[Fix] _LazyError reads name-mangled __data via unmangled literal → AttributeError (#3751) - #3767
Open
yushuosun wants to merge 1 commit into
Open
Conversation
_LazyError and its inner LazyErrorObj store self.__data, which Python mangles
to _LazyError__data / _LazyErrorObj__data, but read it back via
object.__getattribute__(self, "__data") — an unmangled string literal that does
not exist. So when an optional package (e.g. tinycudann) is missing, touching a
lazily-errored object raised AttributeError('__data') instead of the intended
RuntimeError("Could not load package ..."). Use a non-mangled _data name.
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.
Motivation
When an optional dependency such as
tinycudannis not installed, touching the lazily-errored stand-in raises a confusingAttributeError: __datainstead of the intendedRuntimeError("Could not load package tinycudann.")(#3751 — e.g.neus-factoon SDFStudio data fails with_LazyError object has no attribute __data).Root cause
In
nerfstudio/utils/external.py,_LazyErrorand its innerLazyErrorObjstore the payload asself.__data = data. Inside a class,self.__datais name-mangled toself._LazyError__data/self._LazyErrorObj__data. But the__call__/__getattr__methods read it back via:That string literal
"__data"is not name-mangled, so the attribute does not exist — henceAttributeErrorinstead of the helpfulRuntimeError.Modifications
nerfstudio/utils/external.py: store and read the payload under a consistent, non-mangled name_data(replaceself.__dataand theobject.__getattribute__(self, "__data")lookups). This restores the intended "package not installed" error message.Duplicate-check
pulls?state=open&per_page=100 --paginate) for3751/_LazyError/__data→ no references.