Skip to content

Commit 4ac22b6

Browse files
fix: add dry_run to Part.delete() docstring and test coverage
Update Part.delete() kwargs docstring to document the dry_run parameter. Add integration test for Part.delete(dry_run=True) with part_integrity="ignore". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 91bf61b commit 4ac22b6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/datajoint/user_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def delete(self, part_integrity: str = "enforce", **kwargs):
226226
- ``"ignore"``: Allow direct deletion (breaks master-part integrity).
227227
- ``"cascade"``: Delete parts AND cascade up to delete master.
228228
**kwargs: Additional arguments passed to Table.delete()
229-
(transaction, prompt)
229+
(transaction, prompt, dry_run)
230230
231231
Raises:
232232
DataJointError: If part_integrity="enforce" (direct Part deletes prohibited)

tests/integration/test_cascade_delete.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,36 @@ class Child(dj.Manual):
271271
assert Child.is_declared
272272
assert len(Parent()) == 1
273273
assert len(Child()) == 1
274+
275+
276+
def test_part_delete_dry_run(schema_by_backend):
277+
"""dry_run=True on Part.delete() returns affected row counts without deleting."""
278+
279+
@schema_by_backend
280+
class Master(dj.Manual):
281+
definition = """
282+
master_id : int
283+
---
284+
name : varchar(255)
285+
"""
286+
287+
class Detail(dj.Part):
288+
definition = """
289+
-> master
290+
detail_id : int
291+
---
292+
data : varchar(255)
293+
"""
294+
295+
Master.insert1((1, "M1"))
296+
Master.Detail.insert([(1, 1, "D1"), (1, 2, "D2")])
297+
298+
# dry_run with part_integrity="ignore" should return counts without deleting
299+
counts = (Master.Detail & {"master_id": 1}).delete(part_integrity="ignore", dry_run=True)
300+
301+
assert isinstance(counts, dict)
302+
assert counts[Master.Detail.full_table_name] == 2
303+
304+
# Data must still be intact
305+
assert len(Master()) == 1
306+
assert len(Master.Detail()) == 2

0 commit comments

Comments
 (0)