Page MenuHomePhabricator

having an apostrophe in a page name breaks CargoRecreateData.php
Closed, ResolvedPublicBUG REPORT

Description

MW 1.36.2 Cargo 3.0 (5decb5b) 2021-12-09T10:06:57

When I try to run CargoRecreateData.php on a wiki that includes page with title "Dr. Liam O'Neil" it crashes with the following error:

Recreating data for Cargo table Person in 5 seconds... hit [Ctrl]-C to escape.
Deleting and recreating table...
Handling template that adds to this table: Person
Saving data for pages 1 to 500 that call this template...
Wikimedia\Rdbms\DBQueryError from line 1719 of /home/intmed1/wiki.umintmed.ca/includes/libs/rdbms/database/Database.php: Error 1064: You have an error in yo                                                    ur SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Neil'  ORDER BY `_pageName` LIMIT 100' at li                                                    ne 1 (intMedMWdb.umintmed.ca)
Function: CargoSQLQuery::run
Query: SELECT  `_pageName` AS `_pageName`  FROM `mw_cargo__Person`    WHERE `mw_cargo__Person`.`_ID`  IN (SELECT `_rowID` FROM `mw_cargo__Person__SecretaryT                                                    o` WHERE `_value`= 'Dr. Liam O') Neil'  ORDER BY `_pageName` LIMIT 100

#0 /home/intmed1/wiki.umintmed.ca/includes/libs/rdbms/database/Database.php(1703): Wikimedia\Rdbms\Database->getQueryException('You have an err...', 1064, '                                                    SELECT  `_pageN...', 'CargoSQLQuery::...')
#1 /home/intmed1/wiki.umintmed.ca/includes/libs/rdbms/database/Database.php(1678): Wikimedia\Rdbms\Database->getQueryExceptionAndLog('You have an err...', 1                                                    064, 'SELECT  `_pageN...', 'CargoSQLQuery::...')
#2 /home/intmed1/wiki.umintmed.ca/includes/libs/rdbms/database/Database.php(1244): Wikimedia\Rdbms\Database->reportQueryError('You have an err...', 1064, 'S                                                    ELECT  `_pageN...', 'CargoSQLQuery::...', false)
#3 /home/intmed1/wiki.umintmed.ca/includes/libs/rdbms/database/Database.php(1929): Wikimedia\Rdbms\Database->query('SELECT  `_pageN...', 'CargoSQLQuery::...                                                    ', 32)
#4 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/includes/CargoSQLQuery.php(1563): Wikimedia\Rdbms\Database->select(Array, Array, '`mw_cargo__Pers...', 'C                                                    argoSQLQuery::...', Array, NULL)
#5 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/includes/parserfunctions/CargoQuery.php(102): CargoSQLQuery->run()
#6 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(3356): CargoQuery::run(Object(Parser), 'tables=Person', 'fields=_pageNam...', 'where=Secretary.                                                    ..', 'format=list', 'default=')
#7 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(3041): Parser->callParserFunction(Object(PPTemplateFrame_Hash), 'cargo_query', Array)
#8 /home/intmed1/wiki.umintmed.ca/includes/parser/PPFrame_Hash.php(273): Parser->braceSubstitution(Array, Object(PPTemplateFrame_Hash))
#9 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(2955): PPFrame_Hash->expand(Object(PPNode_Hash_Tree))
#10 /home/intmed1/wiki.umintmed.ca/includes/parser/PPFrame_Hash.php(273): Parser->braceSubstitution(Array, Object(PPTemplateFrame_Hash))
#11 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(3230): PPFrame_Hash->expand(Object(PPNode_Hash_Tree))
#12 /home/intmed1/wiki.umintmed.ca/includes/parser/PPFrame_Hash.php(273): Parser->braceSubstitution(Array, Object(PPFrame_Hash))
#13 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(2879): PPFrame_Hash->expand(Object(PPNode_Hash_Tree), 0)
#14 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(1549): Parser->replaceVariables('{{Person\n|First...')
#15 /home/intmed1/wiki.umintmed.ca/includes/parser/Parser.php(639): Parser->internalParse('{{Person\n|First...')
#16 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/includes/CargoUtils.php(582): Parser->parse('{{Person\n|First...', Object(Title), Object(ParserOptions))
#17 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/maintenance/cargoRecreateData.php(164): CargoUtils::parsePageForStorage(Object(Title), '{{Person\n|First                                                    ...')
#18 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/maintenance/cargoRecreateData.php(66): CargoRecreateData->recreateAllDataForTable('Person', false)
#19 /home/intmed1/wiki.umintmed.ca/maintenance/doMaintenance.php(112): CargoRecreateData->execute()
#20 /home/intmed1/wiki.umintmed.ca/extensions/Cargo/maintenance/cargoRecreateData.php(173): require_once('/home/intmed1/w...')
#21 {main}

}

Event Timeline

If it helps to narrow things down, I've got stacks of page names and, separately, field names with apostrophes within them, and never have had this problem with CargoRecreateData.php, and currently I'm using Cargo 3.0 (55f3f72) 22:04, 18 October 2021 (and MW 1.34 - forgive me).

Incidentally, within {{#cargo_query...}} I just use double quotation marks for the fields that contain apostrophes, to avoid similar problems. I avoid having single and double quotation marks in one field, e.g. page name, but it's possible to get round that too by using ParserFunctions (I can't remember how).

I have had the problem you describe before, and if a query breaks where I can see it I know to use double-quotes in a scenario like this. However, this is a query in a template that runs on 100s of pages, and I had not seen the one on which it breaks. The thing I am flagging is that it breaks a maintenance script. I get it that the script can't process this page, but it might have been better if it managed to fail out of this page and continue with others?
It also would be nice if there was a way to see if anything currently breaks Cargo on a given wiki, although that might be a big-ish ask. I suppose it would have to try to run everything on every page and report back if there are errors. Something like SMWs "Constraint Error List" and "Processing Error List".

I have reviewed and fixed the template that broke it, and it really was doing something odd: storing a value in Cargo that it retrieves via SMW ask. Legacy content and quick and dirty fix by the look of it, with emphasis on dirty. So, not good user practice for sure, but it could have failed more gracefully with a better error message, and possibly with continuing on with the rest of the records after the failed one?

For amusement, here is the cargo store...

{{#cargo_store:
_table = Person
|FirstName = {{{FirstName}}}
|LastName = {{{LastName}}}
...
|SecretaryTo = {{#ask:
    [[{{PAGENAME}}]]
    |?Is_SecretaryTo=
    |default=Not a Secretary 
    |mainlabel=-
    |link=none
}} <!-- the info is stored in different template so this nuisance...-->
...
Yaron_Koren claimed this task.
Yaron_Koren subscribed.

I believe this exact issue is no longer a problem.