@@ -810,7 +810,7 @@ def delete_quick(self, get_count=False):
810810 def delete (
811811 self ,
812812 transaction : bool = True ,
813- safemode : bool | None = None ,
813+ prompt : bool | None = None ,
814814 force_parts : bool = False ,
815815 force_masters : bool = False ,
816816 ) -> int :
@@ -821,8 +821,8 @@ def delete(
821821 transaction: If `True`, use of the entire delete becomes an atomic transaction.
822822 This is the default and recommended behavior. Set to `False` if this delete is
823823 nested within another transaction.
824- safemode : If `True`, prohibit nested transactions and prompt to confirm. Default
825- is `dj.config['safemode']`.
824+ prompt : If `True`, show what will be deleted and ask for confirmation.
825+ If `False`, delete without confirmation. Default is `dj.config['safemode']`.
826826 force_parts: Delete from parts even when not deleting from their masters.
827827 force_masters: If `True`, include part/master pairs in the cascade.
828828 Default is `False`.
@@ -916,19 +916,19 @@ def cascade(table):
916916 raise DataJointError ("Exceeded maximum number of delete attempts." )
917917 return delete_count
918918
919- safemode = config ["safemode" ] if safemode is None else safemode
919+ prompt = config ["safemode" ] if prompt is None else prompt
920920
921921 # Start transaction
922922 if transaction :
923923 if not self .connection .in_transaction :
924924 self .connection .start_transaction ()
925925 else :
926- if not safemode :
926+ if not prompt :
927927 transaction = False
928928 else :
929929 raise DataJointError (
930930 "Delete cannot use a transaction within an ongoing transaction. "
931- "Set transaction=False or safemode =False) ."
931+ "Set transaction=False or prompt =False."
932932 )
933933
934934 # Cascading delete
@@ -954,22 +954,22 @@ def cascade(table):
954954
955955 # Confirm and commit
956956 if delete_count == 0 :
957- if safemode :
957+ if prompt :
958958 logger .warning ("Nothing to delete." )
959959 if transaction :
960960 self .connection .cancel_transaction ()
961961 elif not transaction :
962962 logger .info ("Delete completed" )
963963 else :
964- if not safemode or user_choice ("Commit deletes?" , default = "no" ) == "yes" :
964+ if not prompt or user_choice ("Commit deletes?" , default = "no" ) == "yes" :
965965 if transaction :
966966 self .connection .commit_transaction ()
967- if safemode :
967+ if prompt :
968968 logger .info ("Delete committed." )
969969 else :
970970 if transaction :
971971 self .connection .cancel_transaction ()
972- if safemode :
972+ if prompt :
973973 logger .warning ("Delete cancelled" )
974974 return delete_count
975975
@@ -989,15 +989,20 @@ def drop_quick(self):
989989 else :
990990 logger .info ("Nothing to drop: table %s is not declared" % self .full_table_name )
991991
992- def drop (self ):
992+ def drop (self , prompt : bool | None = None ):
993993 """
994994 Drop the table and all tables that reference it, recursively.
995- User is prompted for confirmation if config['safemode'] is set to True.
995+
996+ Args:
997+ prompt: If `True`, show what will be dropped and ask for confirmation.
998+ If `False`, drop without confirmation. Default is `dj.config['safemode']`.
996999 """
9971000 if self .restriction :
9981001 raise DataJointError (
9991002 "A table with an applied restriction cannot be dropped. Call drop() on the unrestricted Table."
10001003 )
1004+ prompt = config ["safemode" ] if prompt is None else prompt
1005+
10011006 self .connection .dependencies .load ()
10021007 do_drop = True
10031008 tables = [table for table in self .connection .dependencies .descendants (self .full_table_name ) if not table .isdigit ()]
@@ -1012,7 +1017,7 @@ def drop(self):
10121017 )
10131018 )
10141019
1015- if config [ "safemode" ] :
1020+ if prompt :
10161021 for table in tables :
10171022 logger .info (table + " (%d tuples)" % len (FreeTable (self .connection , table )))
10181023 do_drop = user_choice ("Proceed?" , default = "no" ) == "yes"
0 commit comments