[3.0] Pass a list of rows to Db::insert(), not a single row - #9576
Merged
Sesquipedalian merged 1 commit intoAug 29, 2026
Merged
Conversation
The fourth argument of Db::$db->insert() has to be an array of rows. Four call sites passed one row's values directly. With $backward_compatibility on the database layer quietly wraps them, but that is off by default in 3.0, and then insert() calls error_backtrace() with E_USER_ERROR and the request dies with "Invalid data structure sent to the database". Logging::trackStats() is the bad one. The UPDATE it tries first matches nothing on the first tracked event of a new day, so the insert runs, so the page is a 500 -- and because the row is never created, so is every page after it, for the rest of the day. That needs 'hitStats' on, or a post, a new topic or a registration to be the first thing tracked. The other three are the moved/merged redirect in Display::checkMovedMergedRedirect(), the spider stats in User::logSpider(), and saving a theme variant in Theme::loadVariant(). NotifyTopic::changePref() has the same fault and is left alone here, because SimpleMachines#9477 already fixes it along with two others on that path. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Sesquipedalian
approved these changes
Aug 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The fourth argument of
Db::$db->insert()has to be an array of rows. Four call sites passone row's values directly. With
$backward_compatibilityon, the database layer quietlywraps them; that is off by default in 3.0, and then
insert()callserror_backtrace()with
E_USER_ERRORand the request dies with "Invalid data structure sent to thedatabase."
Logging::trackStats()is the bad one. TheUPDATEit tries first matches nothing onthe first tracked event of a new day, so the insert runs, so the page is a 500 — and
because the row is never created, so is every page after it, for the rest of the day. It
takes
hitStatsbeing on, or a post, a new topic or a registration being the first thingtracked that day.
Reproduced on a clean install with
hitStatson:smf_log_errorsfills withInvalid data structure sent to the database.<br>Function: trackStatsatSources/Logging.php:494. With this change the first request answers 200,creates the row and increments
hitsfrom then on.The other three are narrower:
Display::checkMovedMergedRedirect()— marking a moved or merged topic read on the waythrough the redirect.
User::logSpider()— the first page a spider fetches each day, whenspider_modeis 1.Theme::loadVariant()— saving a member's chosen theme variant.How this was checked
trackStats()end to end, as above. The other three by inspection: they are the samemisuse of the same argument, and each is unreachable on a stock install without a
configuration this environment does not have — the default theme ships
theme_variants = [], and a spider request dies earlier anyway, onTyped property SMF\User::$timezone must not be accessed before initializationfromSources/Time.php:191, which is a separate bug and unchanged either way.No test: every one of these needs
Db::$db, which the unit suite has no connection for.NotifyTopic::changePref()has the same fault and is deliberately left alone here, because#9477 already fixes it along with two other faults on that path.
Issues References (Fixes|Related|Closes)