[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:
James Reed
2020-12-11 17:53:04 -08:00
committed by Facebook GitHub Bot
parent 29f0fa36b1
commit 76d41c801e
3 changed files with 33 additions and 0 deletions

View File

@ -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));
}