Skip to content

Commit

Permalink
Call mark_as_changed_wrapper for list.clear on ListField
Browse files Browse the repository at this point in the history
`list.clear` was added in Python 3.3
  • Loading branch information
juannyG committed Sep 30, 2024
1 parent 9aab9d2 commit 1758d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions mongoengine/base/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def __setitem__(self, key, value):
remove = mark_as_changed_wrapper(list.remove)
reverse = mark_as_changed_wrapper(list.reverse)
sort = mark_as_changed_wrapper(list.sort)
clear = mark_as_changed_wrapper(list.clear)
__delitem__ = mark_as_changed_wrapper(list.__delitem__)
__iadd__ = mark_as_changed_wrapper(list.__iadd__)
__imul__ = mark_as_changed_wrapper(list.__imul__)
Expand Down
7 changes: 6 additions & 1 deletion tests/test_datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test___iter__(self):
base_list = BaseList(values, instance=None, name="my_name")
assert values == list(base_list)

def test___iter___allow_modification_while_iterating_withou_error(self):
def test___iter___allow_modification_while_iterating_without_error(self):
# regular list allows for this, thus this subclass must comply to that
base_list = BaseList([True, False, True, False], instance=None, name="my_name")
for idx, val in enumerate(base_list):
Expand Down Expand Up @@ -365,6 +365,11 @@ def test_sort_calls_with_key(self):
base_list.sort(key=lambda i: str(i))
assert base_list == [1, 11, 2]

def test_clear_calls_mark_as_changed(self):
base_list = self._get_baselist([True, False])
base_list.clear()
assert base_list._instance._changed_fields == ["my_name"]


class TestStrictDict(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit 1758d23

Please sign in to comment.