File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ Development
1111 Typically to support mock mongo libraries like mongomock, montydb, mongita #2729
1212- BREAKING CHANGE: connecting MongoEngine with mongomock should now use the new `mongo_client_class `
1313 For more info, check https://docs.mongoengine.org/guide/mongomock.html
14+ - Fix DictField that always gets marked as changed #2606
1415
1516Changes in 0.26.0
1617=================
Original file line number Diff line number Diff line change 44
55from mongoengine import *
66from mongoengine .pymongo_support import list_collection_names
7- from tests .utils import MongoDBTestCase
7+ from tests .utils import MongoDBTestCase , get_as_pymongo
88
99
1010class TestDelta (MongoDBTestCase ):
@@ -977,6 +977,24 @@ class MyDoc(Document):
977977 mydoc ._clear_changed_fields ()
978978 assert mydoc ._get_changed_fields () == []
979979
980+ def test_delta_on_dict_empty_key_triggers_full_change (self ):
981+ """more of a bug (harmless) but empty key changes aren't managed perfectly"""
982+
983+ class MyDoc (Document ):
984+ dico = DictField ()
985+
986+ MyDoc .drop_collection ()
987+
988+ MyDoc (dico = {"a" : {"b" : 0 }}).save ()
989+
990+ mydoc = MyDoc .objects .first ()
991+ assert mydoc ._get_changed_fields () == []
992+ mydoc .dico ["" ] = 3
993+ assert mydoc ._get_changed_fields () == ["dico" ]
994+ mydoc .save ()
995+ raw_doc = get_as_pymongo (mydoc )
996+ assert raw_doc == {"_id" : mydoc .id , "dico" : {"" : 3 , "a" : {"b" : 0 }}}
997+
980998
981999if __name__ == "__main__" :
9821000 unittest .main ()
You can’t perform that action at this time.
0 commit comments