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

Call mark_as_changed_wrapper for list.clear on ListField #2858

Merged
merged 1 commit into from
Oct 1, 2024
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 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