This commit is contained in:
matteo porta 2022-11-07 09:27:30 +01:00
parent 96f36193cd
commit 9f236bfd4a
2 changed files with 5 additions and 4 deletions

View File

@ -21,9 +21,10 @@ class Crud_DB:
@db.connection_context()
@db.atomic()
def commit(self, data, deleted_rows=None):
deleted = self.table_model.delete().where(self.table_pk << deleted_rows).execute()
if deleted != len(deleted_rows):
raise AssertionError(f"deleted {deleted} rows instead of the expected {len(deleted_rows)}")
if deleted_rows is not None:
deleted = self.table_model.delete().where(self.table_pk << deleted_rows).execute()
if deleted != len(deleted_rows):
raise AssertionError(f"deleted {deleted} rows instead of the expected {len(deleted_rows)}")
# SQLITE DOES NOT SUPPORT UPDATE, ONLY REPLACE
complete_data = []
for rn, row in enumerate(data):

View File

@ -443,7 +443,7 @@ class Crud(Widget):
# delete rows with primary key changed to avoid duplication if primary key in selected fields and editable
if self.db.table_pk.name in self.select and not (self.readonly is None or self.readonly is True or (self.readonly is not False and self.db.table_pk.name in self.readonly)):
for rn, r in enumerate(data):
if r[self.db.table_pk.name] != self.data_index[rn]:
if self.data_index[rn] is not None and r[self.db.table_pk.name] != self.data_index[rn]:
self.deleted_rows.add(self.data_index[rn])
# INDEX DATA WITH PK
try: