kiota
kiota copied to clipboard
1.9.6 Python: oneOf with primitives not working (wrong exception handler)
What are you generating using Kiota, clients or plugins?
API Client/SDK
In what context or format are you using Kiota?
Nuget tool
Client library/SDK language
None
Describe the bug
In an API that returns a OneOf of primitives and no discriminator, the codegen tries to reference a discriminator of "" , causing a value exception.
Expected behavior
Generated ParseNode should handle no discriminator case properly
How to reproduce
Use latest .net tool to generate api for oneOf, and try to de-serialize.
Open API description file
Kiota Version
1.9.6
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
Patch parse node or factory code?
Configuration
Windows x64
Debug output
No response
Other information
Here is the generated code:
@staticmethod
def create_from_discriminator_value(parse_node: ParseNode) -> My_scalarValue:
if parse_node is None:
raise TypeError("parse_node cannot be null.")
try:
####### Note we look for a mapping_value but never use it
####### This next line will fail, but will throw a ValueError not an AttributeError
####### So we never get past here
child_node = parse_node.get_child_node("")
mapping_value = child_node.get_str_value() if child_node else None
except AttributeError:
mapping_value = None
result = My_scalarValue()
if boolean_value := parse_node.get_bool_value():
result.boolean = boolean_value
elif double_value := parse_node.get_float_value():
result.double = double_value
elif integer_value := parse_node.get_int_value():
result.integer = integer_value
elif string_value := parse_node.get_str_value():
result.string = string_value
return result
Note sure if the version #'s of the tool and the kiota libs have any relation (guess not) But this is the version of the tool I used: