Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit25eb32b

Browse files
fix: results returned byattributes property to show updates
Previously the `attributes` method would show the original values in aGitlab Object even if they had been updated. Correct this so that theupdated value will be returned.Also use copy.deepcopy() to ensure that modifying the dictionary returned cannot also modify the object.
1 parent3b1ede4 commit25eb32b

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

‎gitlab/base.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
importcopy
1819
importimportlib
1920
importpprint
2021
importtextwrap
@@ -243,10 +244,11 @@ def encoded_id(self) -> Optional[Union[int, str]]:
243244

244245
@property
245246
defattributes(self)->Dict[str,Any]:
246-
d=self.__dict__["_updated_attrs"].copy()
247-
d.update(self.__dict__["_attrs"])
248-
d.update(self.__dict__["_parent_attrs"])
249-
returnd
247+
data= {}
248+
data.update(copy.deepcopy(self._parent_attrs))
249+
data.update(copy.deepcopy(self._attrs))
250+
data.update(copy.deepcopy(self._updated_attrs))
251+
returndata
250252

251253

252254
classRESTObjectList:

‎tests/unit/test_base.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def fake_manager(fake_gitlab):
4646
returnFakeManager(fake_gitlab)
4747

4848

49+
@pytest.fixture
50+
deffake_object(fake_manager):
51+
returnFakeObject(fake_manager, {"attr1": [1,2,3]})
52+
53+
4954
classTestRESTManager:
5055
deftest_computed_path_simple(self):
5156
classMGR(base.RESTManager):
@@ -306,3 +311,24 @@ def test_repr(self, fake_manager):
306311

307312
FakeObject._id_attr=None
308313
assertrepr(obj)=="<FakeObject>"
314+
315+
deftest_attributes_get(self,fake_object):
316+
assertfake_object.attr1== [1,2,3]
317+
result=fake_object.attributes
318+
assertresult== {"attr1": [1,2,3]}
319+
320+
deftest_attributes_shows_updates(self,fake_object):
321+
# Updated attribute value is reflected in `attributes`
322+
fake_object.attr1="hello"
323+
assertfake_object.attributes== {"attr1":"hello"}
324+
assertfake_object.attr1=="hello"
325+
# New attribute is in `attributes`
326+
fake_object.new_attrib="spam"
327+
assertfake_object.attributes== {"attr1":"hello","new_attrib":"spam"}
328+
329+
deftest_attributes_is_copy(self,fake_object):
330+
# Modifying the dictionary does not cause modifications to the object
331+
result=fake_object.attributes
332+
result["attr1"].append(10)
333+
assertresult== {"attr1": [1,2,3,10]}
334+
assertfake_object.attributes== {"attr1": [1,2,3]}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp