Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions datajoint/user_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,17 @@ def table_name(cls):
else cls.master.table_name + "__" + from_camel_case(cls.__name__)
)

def delete(self, force=False):
def delete(self, force=False, **kwargs):
"""
unless force is True, prohibits direct deletes from parts.
Unless force is True, prohibits direct deletes from parts.
Accepts any kwargs supported by Table.delete and forwards them to super().delete.
"""
if force:
super().delete(force_parts=True)
else:
raise DataJointError(
"Cannot delete from a Part directly. Delete from master instead"
)
return super().delete(force_parts=True, **kwargs)

raise DataJointError(
"Cannot delete from a Part directly. Delete from master instead"
)

def drop(self, force=False):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from typing import Dict, List

import certifi
import minio
import networkx as nx
import pytest
minio = pytest.importorskip("minio")
import urllib3
from packaging import version

Expand Down
8 changes: 8 additions & 0 deletions tests/test_cascading_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def test_stepwise_delete(schema_simp_pop):
not B()
), "failed to delete from the parent table following child table deletion"

def test_part_delete_forwards_kwargs(schema_simp_pop):
assert not dj.config["safemode"], "safemode must be off for testing"
assert L() and A() and B() and B.C(), "schema population failed"

# Should accept and forward kwargs supported by Table.delete
B.C().delete(force=True, transaction=False)

assert not B.C(), "failed to delete child table with forwarded kwargs"

def test_delete_tree_restricted(schema_simp_pop):
assert not dj.config["safemode"], "safemode must be off for testing"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_relational_operand.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ def test_top_restriction_with_keywords(self, schema_simp_pop):
]
assert key.fetch(as_dict=True) == [
{"id": 2, "key": 6},
{"id": 2, "key": 5},
{"id": 1, "key": 5},
{"id": 2, "key": 5},
{"id": 0, "key": 4},
{"id": 1, "key": 4},
{"id": 2, "key": 4},
Expand Down
Loading