THRIFT-4531: Fix generated Python read() method for immutable structs with optional members
Client: python
This closes #1521.
diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index caa04a8..f8692bb 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -948,6 +948,20 @@
indent_down();
indent(out) << "iprot.readStructBegin()" << endl;
+
+ if (is_immutable(tstruct)) {
+ for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
+ t_field* tfield = *f_iter;
+ std::ostringstream result;
+ result << tfield->get_name() << " = ";
+ if (tfield->get_value() != NULL) {
+ result << render_field_default_value(tfield);
+ } else {
+ result << "None";
+ }
+ indent(out) << result.str() << endl;
+ }
+ }
// Loop over reading in fields
indent(out) << "while True:" << endl;