Fix bug in ConvertPyObjectToAttributeType when type="tensor" and value is a string that's not a Tensor textproto.

PiperOrigin-RevId: 325892441
Change-Id: I4a29954ec32b84fef75859ac36f4e694a0317688
This commit is contained in:
Edward Loper 2020-08-10 14:48:44 -07:00 committed by TensorFlower Gardener
parent 6411114cbd
commit dd2ee4e8cc
2 changed files with 5 additions and 2 deletions

View File

@ -167,8 +167,10 @@ struct ConvertTensorProtoFunctor {
} else if (PY_STRING_CHECK(value)) {
result.reset(PyObject_CallObject(tensor_proto, nullptr));
if (result) {
PyObject_CallFunctionObjArgs(text_format_parse, value, result.get(),
nullptr);
if (!PyObject_CallFunctionObjArgs(text_format_parse, value,
result.get(), nullptr)) {
return nullptr;
}
}
}
return result;

View File

@ -87,6 +87,7 @@ class OpDefUtilTest(test_util.TensorFlowTestCase, parameterized.TestCase):
("list(any)", 12),
("list(int)", [1, "two"]),
("list(string)", [1, "two"]),
("tensor", "string that is not a text-formatted TensorProto"),
])
def testConvertError(self, attr_type, value):
with self.assertRaisesRegex(TypeError, "Failed to convert value"):