From 90b8dd59784e75b4acce51db366a1cb34418847f Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 14 Sep 2023 20:36:04 +0300 Subject: [PATCH] Fix bug in instantiating backed model with keyword args --- kiota_abstractions/store/backed_model.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/kiota_abstractions/store/backed_model.py b/kiota_abstractions/store/backed_model.py index 7a964c3..8d3325e 100644 --- a/kiota_abstractions/store/backed_model.py +++ b/kiota_abstractions/store/backed_model.py @@ -4,7 +4,7 @@ # See License in the project root for license information. # ------------------------------------------------------------------------------ -from dataclasses import dataclass +from dataclasses import dataclass, fields from .backing_store import BackingStore @@ -18,22 +18,15 @@ class BackedModel: def __post_init__(self): self.backing_store.is_initialization_completed = True + for field in fields(self): + if field.name != "backing_store": + field_val = getattr(self, field.name) + if field_val is not field.default: + self.backing_store.set(field.name, field_val) def __setattr__(self, prop, val): if prop == "backing_store": super().__setattr__(prop, val) else: self.backing_store.set(prop, val) - - def __getattribute__(self, prop): - if prop == "backing_store": - return super().__getattribute__(prop) - if self.backing_store.get(prop) is not None: - return self.backing_store.get(prop) - try: - attr = super().__getattribute__(prop) - if callable(attr): # methods such as serialize and get_field_deserializers - return attr - return None - except AttributeError: - return None + super().__setattr__(prop, self.backing_store.get(prop))