Skip to content

fix(Database): reset pretend mode in BaseConnection::prepare() on exception - #10768

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/baseconnection-prepare-pretend-finally
Open

gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/baseconnection-prepare-pretend-finally

Conversation

@gr8man

@gr8man gr8man commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description
When the closure passed to BaseConnection::prepare() threw an exception, pretend(false) was bypassed, leaving the connection in pretend mode. Every subsequent database write on the same connection was then silently discarded, which is particularly harmful in long-lived environments like Worker Mode.

This wraps the closure call in a try/finally block to ensure pretend mode is always reset, and adds a regression test covering the throwing closure.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

…eption

BaseConnection::prepare() enables pretend mode while the user closure builds the query. If the closure threw, the following pretend(false) never ran, leaving the connection in pretend mode. Every later query on the same connection was then silently discarded instead of being executed, which is especially harmful in long-lived processes such as Worker Mode.

Wrap the closure call in try/finally so pretend mode is always reset, and add a regression test covering the throwing closure.
@carson-codeigniter4 carson-codeigniter4 Bot added needs template Opened issues not following the bug form template bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 12, 2026
@carson-codeigniter4

This comment has been minimized.

@carson-codeigniter4 carson-codeigniter4 Bot removed the needs template Opened issues not following the bug form template label Nov 12, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant