microsoft / microsoft/kiota

1.9.6 Python: oneOf with primitives not working (wrong exception handler)

Open
#6,868 2 comments 1 reaction 0 assignees View on GitHub
type:bug
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

### 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

Image

### 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
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the latest .NET tool using the oneOf API description shown in the report, then inspect the generated Python create_from_discriminator_value entry point. Confirm the generated ParseNode handles a primitive oneOf without a discriminator and can deserialize the response without raising a value exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.