Skip to content

Commit 38d47aa

Browse files
Table.delete now returns the number of deleted items
1 parent e13abf5 commit 38d47aa

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

datajoint/external.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,12 @@ def delete(self, *, delete_external_files=None, limit=None, display_progress=Tru
321321
themselves are deleted too.
322322
:param limit: (integer) limit the number of items to delete
323323
:param display_progress: if True, display progress as files are cleaned up
324-
:return: yields
324+
:return: if deleting external files, returns errors
325325
"""
326326
if delete_external_files not in (True, False):
327-
raise DataJointError("The delete_external_files argument must be set to either True or False in delete()")
327+
raise DataJointError(
328+
"The delete_external_files argument must be set to either "
329+
"True or False in delete()")
328330

329331
if not delete_external_files:
330332
self.unused().delete_quick()

datajoint/table.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def delete(self, transaction=True, safemode=None):
398398
:param transaction: if True, use the entire delete becomes an atomic transaction.
399399
:param safemode: If True, prohibit nested transactions and prompt to confirm. Default
400400
is dj.config['safemode'].
401+
:return: number of deleted rows (excluding those from dependent tables)
401402
"""
402403
safemode = config['safemode'] if safemode is None else safemode
403404

@@ -438,6 +439,7 @@ def delete(self, transaction=True, safemode=None):
438439
self.connection.cancel_transaction()
439440
if safemode:
440441
print('Deletes cancelled')
442+
return delete_count
441443

442444
def drop_quick(self):
443445
"""
@@ -821,8 +823,11 @@ def __call__(self, event, skip_logging=None):
821823
logger.info('could not log event in table ~log')
822824

823825
def delete(self):
824-
"""bypass interactive prompts and cascading dependencies"""
825-
self.delete_quick()
826+
"""
827+
bypass interactive prompts and cascading dependencies
828+
:return: number of deleted items
829+
"""
830+
return self.delete_quick(get_count=True)
826831

827832
def drop(self):
828833
"""bypass interactive prompts and cascading dependencies"""

tests/test_foreign_keys.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def test_aliased_fk():
1818
parents = person * parent * link
1919
parents &= dict(full_name="May K. Hall")
2020
assert_equal(set(parents.fetch('parent_name')), {'Hanna R. Walters', 'Russel S. James'})
21-
person.delete()
21+
delete_count = person.delete()
22+
assert delete_count == 16
2223

2324

2425
def test_describe():

0 commit comments

Comments
 (0)