Page MenuHomePhabricator

rebuildrecentchanges.php fails for Postgresql with strings for integers
Closed, ResolvedPublic

Description

Author: john.andrea

Description:
After importing XML dump from a MySQL into empty Postgresql 8.4.8 backend
using rebuildrecentchanges.php fails with:

php maintenance/rebuildrecentchanges.php
Loading from page and revision tables...
$wgRCMaxAge=7862400 (91 days)
Updating links and size differences...
Warning: pg_query(): Query failed: ERROR: invalid input syntax for integer: "NULL"
LINE 1: ...did = '0',rc_new = '1',rc_type = '1',rc_old_len = 'NULL',rc_...

^ in /data/services/wiki/mediawiki-1.17.0/includes/db/DatabasePostgres.php on line 237

A database query syntax error has occurred.
The last attempted database query was:
"UPDATE recentchanges SET rc_last_oldid = '0',rc_new = '1',rc_type = '1',rc_old_len = 'NULL',rc_new_len = '7008' WHERE rc_cur_id = '5' AND rc_this_oldid = '6'"
from within function "RebuildRecentchanges::rebuildRecentChangesTablePass2".
Database returned error "1: ERROR: invalid input syntax for integer: "NULL"
LINE 1: ...did = '0',rc_new = '1',rc_type = '1',rc_old_len = 'NULL',rc_...


Version: 1.17.x
Severity: normal

Details

Reference
bz31007

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:52 PM
bzimport set Reference to bz31007.
bzimport added a subscriber: Unknown Object (MLST).

john.andrea wrote:

Bug appears similar to
https://bugzilla.wikimedia.org/show_bug.cgi?id=13453
which is marked as fixed.

The value for an integer can be NULL, but obviously not the string "NULL".

Looks like a regression in r77778 -- this line:

				$size = !is_null( $size ) ? intval( $size ) : 'NULL';

was meant for generating raw SQL. When passing to the query builder functions, it should pass the NULL value through directly.

Should be fixed in r97544 on trunk.

Merged as r97545 on REL1_18 and r97546 on REL1_17. Shouldn't be needed on 1.17wmf1 as we don't use that script in production much.

You can work around it in your local instance by removing the line listed above in maintenance/rebuildrecentchanges.php.

  • Bug 31648 has been marked as a duplicate of this bug. ***

nedelcumax wrote:

I have some remarks on this fix:

  1. The fix in r97544 won't solve the problem entirely, because the field rc_old_len will take the value of $lastSize which in some cases can be the string 'NULL'. I just unquoted the 'NULL' values and it seemed to work.
  1. Removing this line

    $size = !is_null( $size ) ? intval( $size ) : 'NULL';

As far as I can tell "DatabaseBase::selectField() returns: the value from the field, or false on failure.". Not 100% sure what happens after that, but I think that line should be something like this, instead of being deleted:

$size = ( $size !== false ) ? intval( $size ) : NULL;

Unfortunately I'm not that wiki-expert to know all the implications of all this changes, so maybe someone with more experience can have a look at my observations.

  • Bug 32861 has been marked as a duplicate of this bug. ***

(In reply to comment #5)

[...]
Unfortunately I'm not that wiki-expert to know all the implications of all this
changes, so maybe someone with more experience can have a look at my
observations.

Not being one either, I looked at the code path, and Database::makeList seems to behave like you expected (though it isn't documented). I tested the patch I'll upload in a bit, and it worked fine. Could someone commit it please?

Created attachment 9778
Patch to fix rebuildrecentchanges PostgreSQL bug.

Attached:

  • Bug 36179 has been marked as a duplicate of this bug. ***
Jdforrester-WMF subscribed.

Migrating from the old tracking task to a tag for PostgreSQL-related tasks.