python: primitive oneOf (after deserialization work-around) does not round-trip/reserialize
- 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
Python
### Describe the bug
After making the fix to read a primitive oneOf (#6868 ) the scalar value is lost (set to `{}`) when re-serialized.
### Expected behavior
scalar value should be re-seralized
### How to reproduce
```
obj = <...call my kiota API with scalar oneOf value...>
writer = JsonSerializationWriter()
writer.write_object_value(None, obj)
# We've lost scalar_value prop at this point (other props ok)
bytes = writer.get_serialized_content()
json = bytes.decode('utf-8')
```
So we get to this part:
```
def serialize(self,writer: SerializationWriter) -> None:
....
writer.write_object_value("scalarValue", self.scalar_value)
```
This gets executed correctly:
```
def serialize(self,writer: SerializationWriter) -> None:
...
elif self.double:
writer.write_float_value(None, self.double) # <== Correct
```
but then we get here:
```
def write_object_value(
self, key: Optional[str], value: Optional[U], *additional_values_to_merge: Optional[U]
) -> None:
...
if value or additional_values_to_merge:
temp_writer = self._create_new_writer()
...
if value:
self._serialize_value(temp_writer, value)
...
if key:
# key = 'scalarValue',
# temp_writer.value = 42.0
# However, temp_write.writer is {}, so the value we set is lost
self.writer[key] = temp_writer.writer
else:
self.value = temp_writer.writer
```
So when we finally exit `serialize()`, all the other fields have been set on the object, but the scalar value is not `42.0` but `{}`.
### Open API description file
_No response_
### Kiota Version
1.9.6
### Latest Kiota version known to work for scenario above?(Not required)
_No response_
### Known Workarounds
_No response_
### Configuration
Win x64
### Debug output
Click to expand log
```
```
### Other information
_No response_
Contributor guide
Research direction
Start with JsonSerializationWriter.write_object_value and the scalar oneOf serialize path shown in the report. Reproduce the issue using the provided snippet and inspect how the temporary writer handles the scalar value. Done means a primitive oneOf value such as 42.0 survives serialization and is present in the resulting JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100