-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Fix deserialization of unions BNCH-20706 #41
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
Conversation
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.
Geez, thanks for working through this. Let's figure out a way today to get everything merged in, re-baseline the fixes branch and see if we can get everything stable again but feature complete.
@packyg I'm gonna merge this in the interest of time and avoiding juggling too many balls at the last minute. It would still be great if you could take a read of it when you have time, for context. |
Upstream PR: https://github.com/triaxtec/openapi-python-client/compare/main...benchling:forest-union-2?expand=1
Deserialization of unions in
from_dict
was not working properly, because it failed to account for cases where the union property isNone
orUnset
. This PR adds explicit checks forNone
orUnset
.In addition, the type of the value to deserialize was previously set to
Any
, which was masking type errors. In order to fix these type errors, I introduced a new concept ofcheck_type_for_construct
for each property, which allows the type to be checked before attempting deserialization.In the future, I think we should refine the
try/except
pattern; it's not good practice to rely on a catch-allexcept
when trying to deserialize each type within the union, because we don't know what exception was actually raised.Follow-ups:
NOTE: This fails
openapi-specs
tests, because it's dependent on fixing https://benchling-jira.atlassian.net/browse/BNCH-20726.