Waldemar Kornewald  committed 4d24730

allow to explicitly run count() without a limit (for the fearless potatos who implement their own QuerySets ;). thanks for the patch, Adam Alton

  • Participants
  • Parent commits 00bb5fe
  • Branches default

Comments (0)

Files changed (1)

File db/

     #'exact': '!=', # this might actually become individual '<' and '>' queries
+NOT_PROVIDED = object()
 def safe_call(func):
     def _func(*args, **kwargs):
-    def count(self, limit=None):
+    def count(self, limit=NOT_PROVIDED):
         if self.pk_filters is not None:
             return len(self.get_matching_pk(0, limit))
         if self.excluded_pks:
             return len(list(self.fetch(0, 2000)))
+        # The datastore's Count() method has a 'limit' kwarg, which has
+        # a default value (obviously).  This value can be overridden to anything
+        # you like, and importantly can be overridden to unlimited by passing
+        # a value of None.  Hence *this* method has a default value of
+        # NOT_PROVIDED, rather than a default value of None
         kw = {}
-        if limit is not None:
+        if limit is not NOT_PROVIDED:
             kw['limit'] = limit
         return self._build_query().Count(**kw)
 class SQLUpdateCompiler(NonrelUpdateCompiler, SQLCompiler):
     def execute_sql(self, result_type=MULTI):
         # modify query to fetch pks only and then execute the query
-        # to get all pks 
+        # to get all pks
         pk =
         pks = [row for row in self.results_iter()]
         return len(pks)
     def update_entities(self, pks):
         for pk in pks:
-    @commit_locked    
+    @commit_locked
     def update_entity(self, pk):
         gae_query = self.build_query()
         key = create_key(self.query.get_meta().db_table, pk)
         entity = Get(key)
         if not gae_query.matches_filters(entity):
         qn = self.quote_name_unless_alias
         update_dict = {}
         for field, o, value in self.query.values:
                 value = value.prepare_database_save(field)
                 value = field.get_db_prep_save(value, connection=self.connection)
             if hasattr(value, "evaluate"):
                 assert not value.negated
                 assert not value.subtree_parents
                 value = ExpressionEvaluator(value, self.query, entity,
             if hasattr(value, 'as_sql'):
                 # evaluate expression and return the new value
                 val = value.as_sql(qn, self.connection)