palantir / conjure-python-client

Python client and JSON encoders for use with generated Conjure clients
Apache License 2.0
7 stars 20 forks source link

Support deserializing unknown union variants #129

Closed dtobin closed 1 year ago

dtobin commented 1 year ago

What happened?

When a conjure Python client is deserializing a response from a conjure-compliant server and receives an unknown union variant, it fails with:

  File "/conjure_python_client/_serde/decoder.py", line 96, in decode_conjure_union_type
    type_of_union, conjure_type
ValueError: unknown union type myNewUnionVariant for <class 'MyUnionType'>

With the current behavior, it's not possible for clients to opt into ignoring unknown variants for a particular object, and the entire decoding will fail.

If a conjure-compliant server has an endpoint that returns values containing a union type, this means that conjure Python clients will break if the server ever upgrades to a version that starts returning a new union variant. Conjure Java clients don't have this problem, as their deserialized unions have visitors that require explicitly handling unknown types.

What did you want to happen?

The most robust solution would be to change conjure-python generation to include an unknown variants for unions. It currently does so for enums but not for unions. Compare the generated union code for conjure-python and conjure-java:

As a workaround (since that would be a large change), another option would be to expose a flag to return None for union variants that fail to deserialize rather than failing the entire request.