-
Notifications
You must be signed in to change notification settings - Fork 197
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
Python SDK safe enum deserialization #282
Conversation
Prior to this change python SDK would raise when the API returned an invalid enum value. Given an enum type of `MyAPIEnum` and an invalid value of `""` this error would be raised `ValueError: '' is not a valid MyAPIEnum` Now it will deserialize to `MyAPIEnum.invalid_api_enum_value` Side note: I really wanted to but was unable to dynamically modify the `MyAPIEnum.invalid_api_enum_value` enum member value to be the actual invalid value returned by the API. So `MyAPIEnum.invalid_api_enum_value.value` will always be `"invalid_api_enum_value"`
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.
@jkaster I don't know if kotlin or any other language that raises on bad enum values has a similar solution but I thought I'd put this one up for python.
"@typescript-eslint/no-unused-vars": [ | ||
"warn", {"args": "all", "argsIgnorePattern": "^_"} | ||
], |
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 was seeing Warning: eslint: '_indent' is defined but never used.
for things like streamsPrologue(_indent: string)
.
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.
yeah we need to tweak eslint settings as you did. Thanks!
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.
We needed this in APIX too. Thanks for fixing.
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.
Looks really good.
We still need to fix the offending API endpoints in Looker, though :)
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.
Nicely done, Joel!
Prior to this change python SDK would raise when the API returned an
invalid enum value. Given an enum type of
MyAPIEnum
and an invalidvalue of
""
this error would be raisedValueError: '' is not a valid MyAPIEnum
Now it will deserialize to
MyAPIEnum.invalid_api_enum_value
Side note: I really wanted to but was unable to dynamically modify the
MyAPIEnum.invalid_api_enum_value
enum member value to be the actualinvalid value returned by the API. So
MyAPIEnum.invalid_api_enum_value.value
will always be"invalid_api_enum_value"