@@ -484,6 +484,20 @@ class Animal(Document):
484484 doc .reload ()
485485 Animal .drop_collection ()
486486
487+ def test_reload_sharded_nested (self ):
488+ class SuperPhylum (EmbeddedDocument ):
489+ name = StringField ()
490+
491+ class Animal (Document ):
492+ superphylum = EmbeddedDocumentField (SuperPhylum )
493+ meta = {'shard_key' : ('superphylum.name' ,)}
494+
495+ Animal .drop_collection ()
496+ doc = Animal (superphylum = SuperPhylum (name = 'Deuterostomia' ))
497+ doc .save ()
498+ doc .reload ()
499+ Animal .drop_collection ()
500+
487501 def test_reload_referencing (self ):
488502 """Ensures reloading updates weakrefs correctly
489503 """
@@ -2715,6 +2729,32 @@ def change_shard_key():
27152729
27162730 self .assertRaises (OperationError , change_shard_key )
27172731
2732+ def test_shard_key_in_embedded_document (self ):
2733+ class Foo (EmbeddedDocument ):
2734+ foo = StringField ()
2735+
2736+ class Bar (Document ):
2737+ meta = {
2738+ 'shard_key' : ('foo.foo' ,)
2739+ }
2740+ foo = EmbeddedDocumentField (Foo )
2741+ bar = StringField ()
2742+
2743+ foo_doc = Foo (foo = 'hello' )
2744+ bar_doc = Bar (foo = foo_doc , bar = 'world' )
2745+ bar_doc .save ()
2746+
2747+ self .assertTrue (bar_doc .id is not None )
2748+
2749+ bar_doc .bar = 'baz'
2750+ bar_doc .save ()
2751+
2752+ def change_shard_key ():
2753+ bar_doc .foo .foo = 'something'
2754+ bar_doc .save ()
2755+
2756+ self .assertRaises (OperationError , change_shard_key )
2757+
27182758 def test_shard_key_primary (self ):
27192759 class LogEntry (Document ):
27202760 machine = StringField (primary_key = True )
0 commit comments