Skip to content
Open
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
4 changes: 4 additions & 0 deletions piccolo/query/methods/insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def on_conflict(

###########################################################################

def _validate(self):
if not self.add_delegate._add:
raise ValueError("No rows were specified to insert.")

def _raw_response_callback(self, results: list):
"""
Assign the ids of the created rows to the model instances.
Expand Down
9 changes: 9 additions & 0 deletions tests/table/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def test_add(self):

self.assertIn("Rustaceans", names)

def test_no_rows(self):
with self.assertRaises(ValueError) as manager:
Band.insert().run_sync()

self.assertEqual(
manager.exception.__str__(),
"No rows were specified to insert.",
)

def test_incompatible_type(self):
"""
You shouldn't be able to add instances of a different table.
Expand Down