Skip to content

Commit a024baa

Browse files
Replace safemode parameter with prompt in delete() and drop()
- delete(safemode=...) → delete(prompt=...) - drop() now accepts prompt parameter (was config-only) - Default behavior unchanged (uses config["safemode"]) - More intuitive naming: prompt=False means "don't prompt" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent f081477 commit a024baa

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/datajoint/table.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

src/datajoint/user_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def delete(self, force=False, **kwargs):
221221
force: If True, allow direct deletion from Part table.
222222
If False (default), raise an error.
223223
**kwargs: Additional arguments passed to Table.delete()
224-
(transaction, safemode, force_masters)
224+
(transaction, prompt, force_masters)
225225
226226
Raises:
227227
DataJointError: If force is False (direct Part deletes are prohibited)

src/datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# version bump auto managed by Github Actions:
22
# label_prs.yaml(prep), release.yaml(bump), post_release.yaml(edit)
33
# manually set this version will be eventually overwritten by the above actions
4-
__version__ = "2.0.0a13"
4+
__version__ = "2.0.0a14"

0 commit comments

Comments
 (0)