-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
THRIFT-5693 - fix bug in serialization of enum default values #2783
base: master
Are you sure you want to change the base?
Conversation
we actually don't have python set up in github actions yet so this is not really tested (we only tested that it did not break other languages that's setup in github actions) can you show the diff between old and new compiler generated python code? |
Gotcha, here's a diff of the ThriftTest.thrift generated Python: |
std::ostringstream out; | ||
out << tfield->get_value()->get_integer(); | ||
return out.str(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this diff from ttypes.py
:
@@ -2931,7 +2931,7 @@ class OptionalEnum(object):
)
- def __init__(self, e= Numberz.FIVE,):
+ def __init__(self, e=5,):
self.e = e
def read(self, iprot):
and also this diff:
@@ -7198,7 +7198,7 @@ OptionalBinary.thrift_spec = (
all_structs.append(OptionalEnum)
OptionalEnum.thrift_spec = (
None, # 0
- (1, TType.I32, 'e', None, Numberz.FIVE, ), # 1
+ (1, TType.I32, 'e', None, 5, ), # 1
)
fix_spec(all_structs)
del all_structs
which I think is caused by this part of the change. from the diff I don't think this change is necessary? (it's probably still correct, but the old code generated seems to be better?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. That default value change was because I thought Thrift was generally expecting int values even representing Python enums, but after re-testing I've found that that was only an issue for serialization and deserialization. Removed that change and here's the updated diff: https://gist.github.com/andrewcunnin/ba688afe22f943c7b9f96e67adb3bc53
a69132d
to
e6dd0a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code looks good to me from the diff generated, but I'm not familiar with the python code enough so I'd still prefer to have some tests to verify it, and I failed to run python3 tests locally similar to how we didn't get the CI setup work in #2787 (comment).
obj = self._deserialize(OptionalEnum, self._serialize(self.optional_enum)) | ||
self.assertEquals(obj, self.optional_enum) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excessive blank lines. I think the general python style is 2 blank lines between classes/top level stuff and one blank line between functions inside the same class. here you are making it 3 blank lines between classes.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, you are making it 4 blank lines between the class above and suite
.
For the testing, is running the cross test and running |
we have tests under both |
This change fixes a bug where the default values set in enum fields were unable to be serialized. Previously default enum values were being stored as enum objects upon initialization, where Thrift generally expects I32 values. With the changes in this pull request, serialization and deserialization are fixed and the python 3.4 style enums continue to work as expected.
JIRA ticket here: https://issues.apache.org/jira/browse/THRIFT-5693
[skip ci]
anywhere in the commit message to free up build resources.