Page MenuHomePhabricator

migrateComments.php fails on numerical comment
Closed, ResolvedPublicBUG REPORT

Description

Migrating a wiki from 1.31.6 to 1.35.0 failed for me with this error from the database log (PostgreSQL):

ERROR:  operator does not exist: text = integer at character 1055
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
STATEMENT:  SELECT /* MigrateComments::loadCommentIDs sysadmin@wiki-p... */  comment_id,comment_text  FROM "comment"    WHERE ((comment_hash = 663705717 AND comment_text = '/* TOPs */') OR (comment_hash = -29472803 AND comment_text = '/* Themenspeicher */') ...

The problematic part around character 1055 was

OR (comment_hash = -1801163141 AND comment_text = 2020)

i.e. the value "2020" was not correctly quoted, it should have been

OR (comment_hash = -1801163141 AND comment_text = '2020')

Table "recentchanges" does indeed contain an entry "rc_comment" of just the value "2020".

I assume (without further proof, I don't speak PHP), that some code generating the SQL statement erroneously decides not to quote "2020", because it does not look like a string but a numeral.

Event Timeline

Actually the problem is not in table "recentchanges", but in "revision". A quick and dirty fix is to change "2020" to "2020x". After changing the entry in "recentchanges", the upgrade still failed. I only then saw, that "revision" contained the same entries. After fixing that entry, the upgrade succeeded.

The problem is that putting a numeric string into an array key causes it to be converted to an integer:

php > $a = [ '2020' => 1, '2020x' => 1, '000' => 1 ];
php > foreach ( $a as $k => $v ) { var_dump($k); }
int(2020)
string(5) "2020x"
string(3) "000"

The solution is to cast it back to string. No information is lost because ZEND_HANDLE_NUMERIC() goes to some trouble to avoid casting non-canonical numeric representations to integer.

Change 644634 had a related patch set uploaded (by Tim Starling; owner: Tim Starling):
[mediawiki/core@master] migrateComments: Cast array keys back to string before passing to the DB

https://gerrit.wikimedia.org/r/644634

Change 644634 merged by jenkins-bot:
[mediawiki/core@master] migrateComments: Cast array keys back to string before passing to the DB

https://gerrit.wikimedia.org/r/644634

Change 644647 had a related patch set uploaded (by Reedy; owner: Tim Starling):
[mediawiki/core@REL1_35] migrateComments: Cast array keys back to string before passing to the DB

https://gerrit.wikimedia.org/r/644647

Change 644647 merged by jenkins-bot:
[mediawiki/core@REL1_35] migrateComments: Cast array keys back to string before passing to the DB

https://gerrit.wikimedia.org/r/644647

Reedy assigned this task to tstarling.
Reedy removed a project: Patch-For-Review.