mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-05 16:44:58 +08:00
[JIT] Fix toIValue handling of AttributeError when casting ClassType (#49188)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/49188 Test Plan: Imported from OSS Reviewed By: pbelevich Differential Revision: D25476573 Pulled By: jamesr66a fbshipit-source-id: cec296fae71cc0cdf36bde60417d7d3b1aa84198
This commit is contained in:
committed by
Facebook GitHub Bot
parent
29f0fa36b1
commit
76d41c801e
@ -713,6 +713,15 @@ inline IValue toIValue(
|
||||
const auto& attrType = classType->getAttribute(slot);
|
||||
const auto& attrName = classType->getAttributeName(slot);
|
||||
|
||||
if (!py::hasattr(obj, attrName.c_str())) {
|
||||
throw py::cast_error(c10::str(
|
||||
"Tried to cast object to type ",
|
||||
type->repr_str(),
|
||||
" but object",
|
||||
" was missing attribute ",
|
||||
attrName));
|
||||
}
|
||||
|
||||
const auto& contained = py::getattr(obj, attrName.c_str());
|
||||
userObj->setSlot(slot, toIValue(contained, attrType));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user