File tree 1 file changed +25
-0
lines changed 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -3675,6 +3675,31 @@ def test_delete(self):
3675
3675
# deleted from the database
3676
3676
self .assertEqual (number , 2 )
3677
3677
3678
+ def test_empty_list_embedded_documents_with_unique_field (self ):
3679
+ """
3680
+ Tests that only one document with an empty list of embedded documents
3681
+ that have a unique field can be saved, but if the unique field is
3682
+ also sparse than multiple documents with an empty list can be saved.
3683
+ """
3684
+ class EmbeddedWithUnique (EmbeddedDocument ):
3685
+ number = IntField (unique = True )
3686
+
3687
+ class A (Document ):
3688
+ my_list = ListField (EmbeddedDocumentField (EmbeddedWithUnique ))
3689
+
3690
+ a1 = A (my_list = []).save ()
3691
+ self .assertRaises (NotUniqueError , lambda : A (my_list = []).save ())
3692
+
3693
+ class EmbeddedWithSparseUnique (EmbeddedDocument ):
3694
+ number = IntField (unique = True , sparse = True )
3695
+
3696
+ class B (Document ):
3697
+ my_list = ListField (EmbeddedDocumentField (EmbeddedWithSparseUnique ))
3698
+
3699
+ b1 = B (my_list = []).save ()
3700
+ b2 = B (my_list = []).save ()
3701
+
3702
+
3678
3703
def test_filtered_delete (self ):
3679
3704
"""
3680
3705
Tests the delete method of a List of Embedded Documents
You can’t perform that action at this time.
0 commit comments