@@ -75,7 +75,7 @@ def __repr__(self):
7575 self .actor_id ,
7676 )
7777
78- def chunk (self ):
78+ def chunk (self ) -> bool :
7979 """
8080 Deletes a chunk of this instance's data. Return ``True`` if there is
8181 more work, or ``False`` if the entity has been removed.
@@ -115,7 +115,7 @@ def filter_relations(self, child_relations):
115115 rel for rel in child_relations if rel .params .get ("model" ) not in self .skip_models
116116 )
117117
118- def delete_bulk (self , instance_list ):
118+ def delete_bulk (self , instance_list ) -> bool :
119119 """
120120 Delete a batch of objects bound to this task.
121121
@@ -190,7 +190,7 @@ def extend_relations_bulk(self, child_relations, obj_list):
190190 rel (obj_list ) for rel in default_manager .bulk_dependencies [self .model ]
191191 ]
192192
193- def chunk (self , num_shards = None , shard_id = None ) :
193+ def chunk (self ) -> bool :
194194 """
195195 Deletes a chunk of this instance's data. Return ``True`` if there is
196196 more work, or ``False`` if all matching entities have been removed.
@@ -203,11 +203,6 @@ def chunk(self, num_shards=None, shard_id=None):
203203 if self .order_by :
204204 queryset = queryset .order_by (self .order_by )
205205
206- if num_shards :
207- assert num_shards > 1
208- assert shard_id < num_shards
209- queryset = queryset .extra (where = [f"id %% { num_shards } = { shard_id } " ])
210-
211206 queryset = list (queryset [:query_limit ])
212207 # If there are no more rows we are all done.
213208 if not queryset :
@@ -218,11 +213,6 @@ def chunk(self, num_shards=None, shard_id=None):
218213 # We have more work to do as we didn't run out of rows to delete.
219214 return True
220215
221- def delete_instance_bulk (self , instance_list ):
222- # slow, but ensures Django cascades are handled
223- for instance in instance_list :
224- self .delete_instance (instance )
225-
226216 def delete_instance (self , instance ):
227217 instance_id = instance .id
228218 try :
@@ -268,10 +258,10 @@ def __init__(self, manager, model, query, partition_key=None, **kwargs):
268258
269259 self .partition_key = partition_key
270260
271- def chunk (self ):
272- return self .delete_instance_bulk ()
261+ def chunk (self ) -> bool :
262+ return self ._delete_instance_bulk ()
273263
274- def delete_instance_bulk (self ):
264+ def _delete_instance_bulk (self ) -> bool :
275265 try :
276266 return bulk_delete_objects (
277267 model = self .model ,
0 commit comments