Skip to content

Commit

Permalink
Fix bug in instantiating backed model with keyword args
Browse files Browse the repository at this point in the history
  • Loading branch information
samwelkanda committed Sep 14, 2023
1 parent 95d61d4 commit 90b8dd5
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions kiota_abstractions/store/backed_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))

0 comments on commit 90b8dd5

Please sign in to comment.