Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of _convert_to_dict to avoid modifying nesting SyncedDict objects when calling items or values #269

Merged
merged 3 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Fixed
+++++

- Fixed issues on Windows with ``H5Store``, project import/export, and operations that move files (#264, #266).
- Calling ``items`` or ``values`` on _SyncedDict objects does not mutate nested dictionaries (#234, #269).


[1.3.0] -- 2019-12-20
Expand Down
6 changes: 3 additions & 3 deletions signac/core/synceddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ def keys(self):

def values(self):
self._synced_load()
return self._convert_to_dict(self._data).values()
return self._convert_to_dict(self).values()

def items(self):
self._synced_load()
return self._convert_to_dict(self._data).items()
return self._convert_to_dict(self).items()

def __repr__(self):
return repr(self())
Expand All @@ -279,7 +279,7 @@ def __str__(self):

def _as_dict(self):
with self._suspend_sync():
return self._convert_to_dict(self._data.copy())
return self._convert_to_dict(self)

def __call__(self):
self._synced_load()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_synced_attrdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,18 @@ def test_suspend_sync(self):
self.assertEqual(len(sad), 1)
self.assert_only_read()

def test_nested_types_dict_conversion(self):
"""Ensure that calling methods like items and values does not
change the type of nested dictionaries."""
sad = self.get_sad({'a': {'b': 1}})
assert type(sad['a']) is SAD
sad.items()
assert type(sad['a']) is SAD
sad.values()
assert type(sad['a']) is SAD
sad._as_dict()
assert type(sad['a']) is SAD


if __name__ == '__main__':
unittest.main()