Page MenuHomePhabricator

Upload image, delete and upload it again causes database error with postgresql
Closed, ResolvedPublic

Description

Author: mail

Description:
PHP Debug

Fresh install.

Uploaded a png.

Deleted the png.

Upload the png again.

Get attached error with phpdebug.

This is a fresh install of mediawiki on centos

[root@networkmanager wiki]# php -v
PHP 5.3.3 (cli) (built: Oct 24 2011 08:35:41)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

[root@networkmanager wiki]# postgres -V
postgres (PostgreSQL) 8.4.9


Version: 1.18.x
Severity: normal
OS: Linux

attachment phpdebug.log ignored as obsolete

Details

Reference
bz32822

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 High.Nov 22 2014, 12:02 AM
bzimport set Reference to bz32822.

mail wrote:

running php cleanupUploadStash also causes an error.

[root@networkmanager maintenance]# php cleanupUploadStash.php
Getting list of files to clean up...
PHP Warning: pg_query(): Query failed: ERROR: syntax error at or near "20"
LINE 1: ...OM "uploadstash" WHERE us_timestamp < 2011-12-05 20:05:47 G...

^ in /var/www/wiki/includes/db/DatabasePostgres.php on line 253

Warning: pg_query(): Query failed: ERROR: syntax error at or near "20"
LINE 1: ...OM "uploadstash" WHERE us_timestamp < 2011-12-05 20:05:47 G...

^ in /var/www/wiki/includes/db/DatabasePostgres.php on line 253

A database error has occurred. Did you forget to run maintenance/update.php after upgrading? See: http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script
Query: SELECT us_key FROM "uploadstash" WHERE us_timestamp < 2011-12-05 20:05:47 GMT
Function: UploadStashCleanup::execute
Error: 1 ERROR: syntax error at or near "20"
LINE 1: ...OM "uploadstash" WHERE us_timestamp < 2011-12-05 20:05:47 G...

Looks like something's missing quotes -- eek!

r92081 introduced use of $db->timestamp here without the quotes (previously it was wfTimestamp(TS_MW) which at least produced a number that worked without quotes, though it would have been wrong presumably for some db types such as PG)

r105322 should fix that part on trunk. Looking for the other bit...

Not sure what's up with the initial problem; can you confirm if the 'uploadstash' table is actually present? Maybe the updaters didn't work or didn't get run?

mail wrote:

I didnt need to run the updater as this was a fresh install.

so r105322 should fix my inital problem? i only added this uploadhash one because i thought they might be related. do i need to make a second bug report?

Thanks for the help

mail wrote:

ahh r105322 fixes the maintenance uploadstash. so initial problem is still being looked at.

No, r105322 will fix the second problem (cleanupUploadStash.php)

It looks like your first problem is because the postgresql tables.sql in 1.18.0 didn't get updated to include the uploadstash table!

r100640 added the table to postgres's tables.sql, but didn't make it into 1.18.0. Looks like it may also be missing an updater...

mail wrote:

Thanks for looking into this. So i will have to wait for the next point release to create my site with postgresql? or will r100640 get merged into trunk and i can pull off the svn/git?

r105349 on REL1_18 should fix it on the branch for the next point release.

You should be able to pull the files out of SVN on trunk or on the branch -- if you want you can probably just grab this and run it into your db:

https://svn.wikimedia.org/viewvc/mediawiki/branches/REL1_18/phase3/maintenance/postgres/archives/patch-uploadstash.sql?view=markup

mail wrote:

No luck there. Added that to the database and still get the same error. Its ok i will keep going without images untill next release.

mail wrote:

Have pulled down the latest svn

svn checkout http://svn.wikimedia.org/svnroot/mediawiki/branches/REL1_18/phase3

and installed from scratch with new database.

Same issue as before as i can see. uploading new php.log

mail wrote:

7/12/11

Attached:

avtargill wrote:

Debian 6.0
PostgreSQL 8.4
PHP 5.3

I can confirm that uploading any attachments (not just images) is not possible with the svn branch mentioned in comment #13. Running the maintenance/update.php script creates the missing table:

mediawiki | uploadstash | table | test_wiki_user

But if I upload a file, delete it, and then try uploading it again this error appears:

Warning: Invalid argument supplied for foreach() in /var/www/test-wiki/includes/db/Database.php on line 2253
Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near ")" LINE 1: ...Stash::stashFile Jon Doe */ FROM "uploadstash" WHERE ) ^ in /var/www/test-wiki/includes/db/DatabasePostgres.php on line 253

I'm not sure if I need to attach any more logs since there already is one here but here are links if required:

With $wgShowExceptionDetails set to true: http://pastebin.com/raw.php?i=myPhBM31
Excerpt from Postgres' log: http://pastebin.com/raw.php?i=TYbncnBm

Making these changes manually doesn't help https://svn.wikimedia.org/viewvc/mediawiki/branches/REL1_18/phase3/maintenance/postgres/archives/patch-uploadstash.sql?revision=105349&view=co

avtargill wrote:

Uploads seem to work if "Ignore any warnings" is checked.

Created attachment 9828
Possible fix - patch to includes/upload/UploadStash.php

Could you try this one-line patch to includes/upload/UploadStash.php?

The unique indexes parameter on Database::replace() is labeled as taking an array; on MySQL it'll be falling through to the native REPLACE behavior which probably doesn't need it to be an array so it got through sloppily.

(Note that this code doesn't appear to be in 1.19 where this func has changed a lot, so it may not happen on 1.19 at all.)

Attached:

Moving to 1.19.0 as 1.18 is released.

Can somebody please review the patch in comment 17 and afterwards replace the "patch-need-review" keyword by "patch-reviewed"?

karun.84 wrote:

(In reply to comment #19)

Can somebody please review the patch in comment 17 and afterwards replace the
"patch-need-review" keyword by "patch-reviewed"?

Hi, the reviews are now down using Gerrit. I am going to test it, and then submit it to Gerrit.

karun.84 wrote:

(In reply to comment #19)

Can somebody please review the patch in comment 17 and afterwards replace the
"patch-need-review" keyword by "patch-reviewed"?

A patch has already been submitted previously that fixes this bug. Ive tested it and I do not receive any errors.

Jdforrester-WMF subscribed.

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