Fixed error message when serializing with required fields missing.
diff --git a/python/message.c b/python/message.c index 45c70e9..0b501fc 100644 --- a/python/message.c +++ b/python/message.c
@@ -1328,6 +1328,18 @@ if (!pb) { PyUpb_ModuleState* state = PyUpb_ModuleState_Get(); + PyObject* errors = PyUpb_CMessage_FindInitializationErrors(_self, NULL); + if (PyList_Size(errors) != 0) { + PyObject* comma = PyUnicode_FromString(","); + PyObject* missing_fields = PyUnicode_Join(comma, errors); + PyErr_Format(state->encode_error_class, + "Message %s is missing required fields: %U", + upb_msgdef_fullname(msgdef), missing_fields); + Py_XDECREF(comma); + Py_XDECREF(missing_fields); + Py_DECREF(errors); + goto done; + } PyErr_Format(state->encode_error_class, "Failed to serialize proto"); goto done; }
diff --git a/python/pb_unit_tests/reflection_test_wrapper.py b/python/pb_unit_tests/reflection_test_wrapper.py index 76e3091..f182ccd 100644 --- a/python/pb_unit_tests/reflection_test_wrapper.py +++ b/python/pb_unit_tests/reflection_test_wrapper.py
@@ -45,8 +45,6 @@ reflection_test.SerializationTest.testFieldDataDescriptor.__unittest_expecting_failure__ = True reflection_test.SerializationTest.testFieldProperties.__unittest_expecting_failure__ = True reflection_test.SerializationTest.testInitArgsUnknownFieldName.__unittest_expecting_failure__ = True -reflection_test.SerializationTest.testSerializeUninitialized.__unittest_expecting_failure__ = True -reflection_test.SerializationTest.testSerializeUninitializedSubMessage.__unittest_expecting_failure__ = True if __name__ == '__main__': unittest.main(module=reflection_test, verbosity=2)