From 7f0d4c1dc2470067b6e4b22c6ab2491b52d3b0e4 Mon Sep 17 00:00:00 2001 From: Andrea Peruffo Date: Mon, 20 May 2024 11:43:51 +0100 Subject: [PATCH] initial fixes for oneOf in python --- src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs index 67eee514f2..a1bcb3b5b2 100644 --- a/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs @@ -508,7 +508,7 @@ private void WriteDeserializerBodyForUnionModel(CodeMethod method, CodeClass par .ThenBy(static x => x.Name) .Select(static x => x.Name)) { - writer.StartBlock($"if self.{otherPropName}:"); + writer.StartBlock($"if hasattr(self, \"{otherPropName}\"):"); writer.WriteLine($"return self.{otherPropName}.{method.Name}()"); writer.DecreaseIndent(); } @@ -659,7 +659,7 @@ private void WriteSerializerBodyForUnionModel(CodeClass parentClass, LanguageWri .OrderBy(static x => x, CodePropertyTypeForwardComparer) .ThenBy(static x => x.Name)) { - writer.StartBlock($"{(includeElse ? "el" : string.Empty)}if self.{otherProp.Name}:"); + writer.StartBlock($"{(includeElse ? "el" : string.Empty)}if hasattr(self, \"{otherProp.Name}\"):"); writer.WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(None, self.{otherProp.Name})"); writer.DecreaseIndent(); if (!includeElse) @@ -676,7 +676,7 @@ private void WriteSerializerBodyForIntersectionModel(CodeClass parentClass, Lang .OrderBy(static x => x, CodePropertyTypeBackwardComparer) .ThenBy(static x => x.Name)) { - writer.StartBlock($"{(includeElse ? "el" : string.Empty)}if self.{otherProp.Name}:"); + writer.StartBlock($"{(includeElse ? "el" : string.Empty)}if hasattr(self, \"{otherProp.Name}\"):"); writer.WriteLine($"writer.{GetSerializationMethodName(otherProp.Type)}(None, self.{otherProp.Name})"); writer.DecreaseIndent(); if (!includeElse)