From 90b8dd59784e75b4acce51db366a1cb34418847f Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 14 Sep 2023 20:36:04 +0300 Subject: [PATCH 1/4] 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)) From a172babf1d8e99fc1f482b980597c5892022e13b Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 14 Sep 2023 20:36:12 +0300 Subject: [PATCH 2/4] Update tests --- tests/store/test_backed_model.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/store/test_backed_model.py b/tests/store/test_backed_model.py index d0a139a..c3ebc61 100644 --- a/tests/store/test_backed_model.py +++ b/tests/store/test_backed_model.py @@ -16,12 +16,11 @@ def test_backed_model_return_only_changed_values_false(mock_user): def test_backed_model_return_only_changed_values_true(mock_user): # Set the backing store to only return changed values mock_user.backing_store.return_only_changed_values = True - # No changes have been made to the backing store, getters should return None - assert mock_user.id is None - assert mock_user.odata_type is None - assert mock_user.business_phones is None + # No changes have been made to the backing store + # enumerate should return an empty list + assert mock_user.backing_store.enumerate_() == [] # change a property value mock_user.business_phones = ["+1 234 567 8901"] # returns the changed value - assert mock_user.business_phones == ["+1 234 567 8901"] + assert mock_user.backing_store.enumerate_() == [('business_phones', (["+1 234 567 8901"], 1))] \ No newline at end of file From 0040d7cc26ad598a59ab28af387d7816346d9a17 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 14 Sep 2023 20:39:36 +0300 Subject: [PATCH 3/4] Bump package version --- kiota_abstractions/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiota_abstractions/_version.py b/kiota_abstractions/_version.py index 795b6a9..95123c9 100644 --- a/kiota_abstractions/_version.py +++ b/kiota_abstractions/_version.py @@ -1 +1 @@ -VERSION: str = "0.8.3" +VERSION: str = "0.8.4" From 8b17e43f44774e110a0055e387b641125a3f8526 Mon Sep 17 00:00:00 2001 From: samwelkanda Date: Thu, 14 Sep 2023 20:42:27 +0300 Subject: [PATCH 4/4] Add CHANGELOG entry --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d06f2c..c7a3cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.4] - 2023-09-14 + +### Added + +### Changed +- Fix error when instantiating BackedModel using positional and keyword arguments + ## [0.8.3] - 2023-09-13 ### Added