Skip to content

Commit 7f442f7

Browse files
committed
Merge pull request #978
2 parents 01f4dd8 + 0ee3203 commit 7f442f7

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,4 @@ that much better:
220220
* Michael Chase (https://github.com/rxsegrxup)
221221
* Eremeev Danil (https://github.com/elephanter)
222222
* Catstyle Lee (https://github.com/Catstyle)
223+
* Kiryl Yermakou (https://github.com/rma4ok)

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Changes in 0.9.X - DEV
1515
- Fixed storage of microseconds in ComplexDateTimeField and unused separator option. #910
1616
- Django support was removed and will be available as a separate extension. #958
1717
- Don't send a "cls" option to ensureIndex (related to https://jira.mongodb.org/browse/SERVER-769)
18+
- Fix for updating sorting in SortedListField. #978
1819
1920
Changes in 0.9.0
2021
================

mongoengine/base/document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def _get_changed_fields(self, inspected=None):
547547
EmbeddedDocument = _import_class("EmbeddedDocument")
548548
DynamicEmbeddedDocument = _import_class("DynamicEmbeddedDocument")
549549
ReferenceField = _import_class("ReferenceField")
550+
SortedListField = _import_class("SortedListField")
550551
changed_fields = []
551552
changed_fields += getattr(self, '_changed_fields', [])
552553

@@ -577,6 +578,12 @@ def _get_changed_fields(self, inspected=None):
577578
if (hasattr(field, 'field') and
578579
isinstance(field.field, ReferenceField)):
579580
continue
581+
elif (isinstance(field, SortedListField) and field._ordering):
582+
# if ordering is affected whole list is changed
583+
if any(map(lambda d: field._ordering in d._changed_fields, data)):
584+
changed_fields.append(db_field_name)
585+
continue
586+
580587
self._nestable_types_changed_fields(
581588
changed_fields, key, data, inspected)
582589
return changed_fields

tests/fields/fields.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,13 @@ class BlogPost(Document):
916916
self.assertEqual(post.comments[0].content, comment2.content)
917917
self.assertEqual(post.comments[1].content, comment1.content)
918918

919+
post.comments[0].order = 2
920+
post.save()
921+
post.reload()
922+
923+
self.assertEqual(post.comments[0].content, comment1.content)
924+
self.assertEqual(post.comments[1].content, comment2.content)
925+
919926
BlogPost.drop_collection()
920927

921928
def test_reverse_list_sorting(self):

0 commit comments

Comments
 (0)