[3.0] Reports failed queries on PostgreSQL instead of swallowing them - #9341
Merged
live627 merged 3 commits intoAug 2, 2026
Merged
Conversation
04b4ad1 took the error handling out of query() in both database APIs. 44c6b13 put it back for MySQL a few months later; PostgreSQL was never given the same treatment, so for the last two years a failing statement there has returned false from an error-suppressed pg_query() and gone no further. Nothing is written to log_errors, nothing is shown, and callers that pass db_error_skip have been passing it to code that could not have honoured it either way. This is the same block MySQL uses, so both APIs behave alike again. The aborted-transaction case is already covered: error_insert() rolls back an open transaction before it writes the row. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This was referenced Aug 1, 2026
live627
requested changes
Aug 2, 2026
live627
left a comment
Contributor
There was a problem hiding this comment.
Could you remove the following four lines?
SMF/Sources/Db/APIs/PostgreSQL.php
Lines 684 to 687 in fcbc3cb
Those null checks aren't necessary:
https://stackoverflow.com/a/2950415/4710434
Removing them also helps keep the MySQL and PostgreSQL database files as similar as possible, making them easier to maintain.
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Collaborator
Author
|
Both done, thanks.
Verified on PostgreSQL 17:
|
live627
approved these changes
Aug 2, 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
A failing query on PostgreSQL goes nowhere.
query()ends with:falsecomes back, the warning is suppressed, and that is the end of it. Nothing is written tolog_errors, nothing is shown, and the request carries on as if the statement had run. Callers that ask to opt out of error reporting by passingdb_error_skip— there are around thirty of them, in the installer, the migrations,Unread,Fulltextand elsewhere — have been handing that flag to code that could not have honoured it either way.This is not deliberate. 04b4ad1 took the block out of both database APIs in Dec 2023. 44c6b13 ("Show query errors") put it back for MySQL in Mar 2024. PostgreSQL was never given the same treatment, so the two APIs have disagreed about what a failed query means for the last two years.
This ports that MySQL block verbatim, so both behave alike again.
The aborted-transaction case that is specific to PostgreSQL is already handled: a failed statement poisons the rest of the transaction, but
error_insert()rolls an open transaction back before it writes the log row, so the error still gets recorded.What it exposes
This is the point of the change, but it is worth being explicit: turning silence into errors makes existing breakage visible, and there was some. Running a forum with this applied and exercising 31 pages plus posting, starting topics, sending PMs, searching, marking read and a full recount surfaced exactly two failing queries, both real bugs that had been quietly doing nothing:
Draft::saveToDatabase(),SET type = <unix timestamp>into atinyintConfig::updateModSettings(),SET value = value + 1on a text columntotalMessages,totalTopics,totalMembers,unapprovedMembersnever movedBoth should land before this one. On their own they are invisible; with this change they become a Database Error page, the second one on every post. With them in place, the sweep above is clean.
Two more pre-existing faults turned up alongside them. Neither is a query failure and neither is affected by this change, but they are worth recording:
Calendar::show()callsErrorHandler::fatalLang('calendar_off', false, 403), where the third parameter is$sprintfand wants an array. Any hit on?action=calendarwith the calendar disabled is a TypeError rather than the intended 403.Sources/PersonalMessage/PM.phpusesUserDataset::MinimalandUserDataset::Noneat lines 1607, 1670 and 1917 but never importsSMF\UserDataset, so it resolves toSMF\PersonalMessage\UserDataset. Sending a PM fatals with "Class not found" on any database.Testing
Docker environment, PostgreSQL 17.
ERROR: smallint out of range,File: /var/www/html/Sources/Draft.php,Line: 704— and logs a row inlog_errorswitherror_type = database.vendor/bin/phpunit— 108 tests, 157 assertions, OK.Issues References (Fixes|Related|Closes)
Related to #9339, #9340