Page MenuHomePhabricator

cargoRecreateData.php exits for every sql error caused by {{#cargo_query}}
Closed, ResolvedPublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • add a faulty query to any table declaring template or templates called within that template
    • e.g., {{#vardefine:testvar|}} {{#cargo_query:tables=my_table|fields=my_field|where=_pageID = {{#var:testvar}} }}
    • the var is added to demonstrate a bit more complexity when designing queries, the final sql will contain an empty where condition like WHERE _pageID =
  • run cargoRecreateData.php --table=my_table

What happens?:
the cargoRecreateData.php maintenance script prematurely exits with status 1

What should have happened instead?:
well, this is of course highly debatable, but I propose that the cargoRecreateData.php script doesn't necessarily need to exit with status 1 for every sql error caused by a cargo query call; in our case it's more likely to be a display issue rather than a storage issue

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc.:
Cargo since b68e9128a77843f91ca152fa3c96c6e6ecd6565b

Proposed "fix"
based on commit b68e9128a77843f91ca152fa3c96c6e6ecd6565b, i'd propose to catch exceptions caused after calling CargoSQLQuery::run(). this would be consistent with the actual $sqlQuery->run() at line 147 in CargoQuery.php in the same commit.

diff --git a/includes/parserfunctions/CargoQuery.php b/includes/parserfunctions/CargoQuery.php                                                                                                                  
index 6b1f0e1..498ee21 100644
--- a/includes/parserfunctions/CargoQuery.php
+++ b/includes/parserfunctions/CargoQuery.php
@@ -96,10 +96,10 @@ class CargoQuery {
            }
            $sqlQueryJustForResultsTitle = CargoSQLQuery::newFromValues( $tablesStr, $newFieldsStr, $whereStr, $joinOnStr,
                $groupByStr, $havingStr, $orderByStr, '', $offsetStr );
+           $queryResultsJustForResultsTitle = $sqlQueryJustForResultsTitle->run();
        } catch ( Exception $e ) { 
            return CargoUtils::formatError( $e->getMessage() );
        }
-       $queryResultsJustForResultsTitle = $sqlQueryJustForResultsTitle->run();
        // Let's collect all special _pageID entries
        $pageIdForBacklinks = []; 
        foreach ( $fieldsToCollectForPageIds as $fieldToCollectForPageIds ) {

what's your opinion on this?

Event Timeline

well... next to maintenance scripts, the change affects actual requests that parse wikitext with cargo queries in them, such as: saving a templates, accessing Special:FormEdit, ...

but w/ the above change why doesn't the {{#cargo query}} parser function display the error message in the catch block instead?

Change 792657 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/Cargo@master] Fix for b68e9128a778 - catch errors from backlinks query

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

Change 792657 merged by jenkins-bot:

[mediawiki/extensions/Cargo@master] Fix for b68e9128a778 - catch errors from backlinks query

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

Yaron_Koren claimed this task.
Yaron_Koren subscribed.

Sorry for the delay - I believe this is fixed now.