Skip to content
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

Merged
merged 1 commit into from
Jul 31, 2020
Merged

Conversation

joeldodge79
Copy link
Contributor

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"

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"`
Copy link
Contributor Author

@joeldodge79 joeldodge79 left a 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.

Comment on lines +137 to +139
"@typescript-eslint/no-unused-vars": [
"warn", {"args": "all", "argsIgnorePattern": "^_"}
],
Copy link
Contributor Author

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).

Copy link
Contributor

@jkaster jkaster Jul 30, 2020

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!

Copy link
Contributor

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.

Copy link
Contributor

@jkaster jkaster left a 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 :)

Copy link
Contributor

@josephaxisa josephaxisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, Joel!

@joeldodge79 joeldodge79 merged commit 16f0b2e into master Jul 31, 2020
@joeldodge79 joeldodge79 deleted the joeldodge/python-enum-fix branch July 31, 2020 17:10
This was referenced Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants