From 9dcc7f6d9d00d310658636445e4933f08cb3b272 Mon Sep 17 00:00:00 2001 From: Jochen <70581149+jtopenpetition@users.noreply.github.com> Date: Wed, 14 Jun 2023 12:28:15 +0200 Subject: [PATCH] allow inserts with primary key nulled to be rolled back when the row to be inserted contains `null` for its primary key column, it's most likely, that it's an auto-increment or otherwise generated primary key, so the row value is not reliable. in that particular case, prefer the last insert id over the row value --- src/Codeception/Module/Db.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Module/Db.php b/src/Codeception/Module/Db.php index db418bd3..2143aaf5 100644 --- a/src/Codeception/Module/Db.php +++ b/src/Codeception/Module/Db.php @@ -808,7 +808,9 @@ private function addInsertedRow(string $table, array $row, $id): void { $primaryKey = $this->_getDriver()->getPrimaryKey($table); $primary = []; - if ($primaryKey !== []) { + if (count($primaryKey) == 1 && is_null($row[$primaryKey[0]])) { + $primary[$primaryKey[0]] = $id; + } elseif ($primaryKey !== []) { $filledKeys = array_intersect($primaryKey, array_keys($row)); $missingPrimaryKeyColumns = array_diff_key($primaryKey, $filledKeys);