@@ -750,6 +750,49 @@ class SomeKind(ndb.Model):
750750 results [0 ].foo
751751
752752
753+ @pytest .mark .usefixtures ("client_context" )
754+ def test_multiquery_with_order_by_key (ds_entity ):
755+ """Verify multiqueries work when ordering by key"""
756+
757+ for i in range (5 ):
758+ entity_id = test_utils .system .unique_resource_id ()
759+ ds_entity (KIND , entity_id , foo = i )
760+
761+ class SomeKind (ndb .Model ):
762+ foo = ndb .IntegerProperty ()
763+
764+ query = (
765+ SomeKind .query ()
766+ .order (SomeKind .key )
767+ .filter (ndb .OR (SomeKind .foo == 4 , SomeKind .foo == 3 , SomeKind .foo == 1 ))
768+ )
769+
770+ results = eventually (query .fetch , length_equals (3 ))
771+ assert [entity .foo for entity in results ] == [1 , 3 , 4 ]
772+
773+ @pytest .mark .usefixtures ("client_context" )
774+ def test_multiquery_with_order_value_by_key (ds_entity , client_context ):
775+ """Check ordering by key values an Entity references"""
776+ project = client_context .client .project
777+ namespace = client_context .get_namespace ()
778+
779+ for i in range (5 ):
780+ entity_id = test_utils .system .unique_resource_id ()
781+ ds_entity (KIND , entity_id , foo = i , bar = ds_key_module .Key ("test_key" , i + 1 , project = project , namespace = namespace ))
782+
783+ class SomeKind (ndb .Model ):
784+ foo = ndb .IntegerProperty ()
785+ bar = ndb .KeyProperty ()
786+
787+ query = (
788+ SomeKind .query ()
789+ .order (SomeKind .bar )
790+ .filter (ndb .OR (SomeKind .foo == 4 , SomeKind .foo == 3 , SomeKind .foo == 1 ))
791+ )
792+
793+ results = eventually (query .fetch , length_equals (3 ))
794+ assert [entity .foo for entity in results ] == [1 , 3 , 4 ]
795+
753796@pytest .mark .usefixtures ("client_context" )
754797def test_count_with_multi_query (ds_entity ):
755798 for i in range (5 ):
0 commit comments