Skip to content

Commit 41abbe2

Browse files
xurshudyanXurshudyan
andauthored
Ensure pretending state is always reset (#57968)
Co-authored-by: Xurshudyan <[email protected]>
1 parent 6ef7343 commit 41abbe2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,14 +646,16 @@ public function pretend(Closure $callback)
646646
return $this->withFreshQueryLog(function () use ($callback) {
647647
$this->pretending = true;
648648

649-
// Basically to make the database connection "pretend", we will just return
650-
// the default values for all the query methods, then we will return an
651-
// array of queries that were "executed" within the Closure callback.
652-
$callback($this);
653-
654-
$this->pretending = false;
655-
656-
return $this->queryLog;
649+
try {
650+
// Basically to make the database connection "pretend", we will just return
651+
// the default values for all the query methods, then we will return an
652+
// array of queries that were "executed" within the Closure callback.
653+
$callback($this);
654+
655+
return $this->queryLog;
656+
} finally {
657+
$this->pretending = false;
658+
}
657659
});
658660
}
659661

0 commit comments

Comments
 (0)