Skip to content

Commit 35f8bf3

Browse files
committed
Fixes lastrowid not being returned correctly in duplicate
Old code was trying to get the lastrowid after the entire list of queries ran, which would return None due to the insert being buried in the list of queries. We now grab it after the insert runs by chacking if it has been set yet, and if the result has a lastrowid
1 parent 9628f65 commit 35f8bf3

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pysimplesql/pysimplesql.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -6472,6 +6472,7 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
64726472
tmp_table = self.quote_table(f"temp_{dataset.table}")
64736473
pk_column = self.quote_column(dataset.pk_column)
64746474
description_column = self.quote_column(dataset.description_column)
6475+
pk = None # we will update this later...
64756476

64766477
# Create tmp table, update pk column in temp and insert into table
64776478
query = [
@@ -6492,9 +6493,9 @@ def duplicate_record(self, dataset: DataSet, children: bool) -> pd.DataFrame:
64926493
res = self.execute(q)
64936494
if res.attrs["exception"]:
64946495
return res
6495-
6496-
# Now we save the new pk
6497-
pk = res.attrs["lastrowid"]
6496+
if pk is None and res.attrs["lastrowid"] is not None:
6497+
# Now we save the new pk
6498+
pk = res.attrs["lastrowid"]
64986499

64996500
# create list of which children we have duplicated
65006501
child_duplicated = []

0 commit comments

Comments
 (0)