@@ -386,6 +386,9 @@ def _Dynamic_RunQuery(self, query, query_result):
386
386
387
387
app = query .app ()
388
388
389
+ query_result .mutable_cursor ().set_cursor (0 )
390
+ query_result .set_more_results (False )
391
+
389
392
if self .__require_indexes :
390
393
required , kind , ancestor , props , num_eq_filters = datastore_index .CompositeIndexForQuery (query )
391
394
if required :
@@ -418,8 +421,6 @@ def _Dynamic_RunQuery(self, query, query_result):
418
421
# the types of the properties)...
419
422
prototype = self .__db [collection ].find_one ()
420
423
if prototype is None :
421
- query_result .mutable_cursor ().set_cursor (0 )
422
- query_result .set_more_results (False )
423
424
return
424
425
prototype = datastore .Entity ._FromPb (self .__entity_for_mongo_document (prototype ))
425
426
@@ -446,20 +447,24 @@ def _Dynamic_RunQuery(self, query, query_result):
446
447
447
448
(key , value ) = self .__filter_binding (prop , filter_val_list [0 ], op , prototype )
448
449
449
- # TODO this can't be the right way to handle this case... need more tests
450
450
if key in spec :
451
- query_result .mutable_cursor ().set_cursor (0 )
452
- query_result .set_more_results (False )
453
- return
454
-
455
- spec [key ] = value
451
+ if not isinstance (spec [key ], types .DictType ) and not isinstance (value , types .DictType ):
452
+ if spec [key ] != value :
453
+ return
454
+ elif not isinstance (spec [key ], types .DictType ):
455
+ value ["$in" ] = [spec [key ]]
456
+ spec [key ] = value
457
+ elif not isinstance (value , types .DictType ):
458
+ spec [key ]["$in" ] = [value ]
459
+ else :
460
+ spec [key ].update (value )
461
+ else :
462
+ spec [key ] = value
456
463
457
464
cursor = self .__db [collection ].find (spec )
458
465
459
466
order = self .__translate_order_for_mongo (query .order_list (), prototype )
460
467
if order is None :
461
- query_result .mutable_cursor ().set_cursor (0 )
462
- query_result .set_more_results (False )
463
468
return
464
469
if order :
465
470
cursor = cursor .sort (order )
@@ -476,13 +481,13 @@ def _Dynamic_RunQuery(self, query, query_result):
476
481
self .__queries [cursor_index ] = cursor
477
482
478
483
query_result .mutable_cursor ().set_cursor (cursor_index )
479
- query_result .set_more_results (True ) # see if we can get away with always feigning more results
484
+ query_result .set_more_results (True )
480
485
481
486
def _Dynamic_Next (self , next_request , query_result ):
482
487
cursor = next_request .cursor ().cursor ()
488
+ query_result .set_more_results (False )
483
489
484
490
if cursor == 0 : # we exited early from the query w/ no results...
485
- query_result .set_more_results (False )
486
491
return
487
492
488
493
try :
@@ -496,7 +501,6 @@ def _Dynamic_Next(self, next_request, query_result):
496
501
try :
497
502
query_result .result_list ().append (self .__entity_for_mongo_document (cursor .next ()))
498
503
except StopIteration :
499
- query_result .set_more_results (False )
500
504
return
501
505
query_result .set_more_results (True )
502
506
0 commit comments