Page MenuHomePhabricator

Pages with _rowID instead of _pageID shows error message when #cargo_query
Closed, ResolvedPublicBUG REPORT

Description

*When I try to query a table's list field as a table, for example here Vocabulary__buchong as a table when buchong is one of table Vocabulary's list field:

{{#cargo_query:
tables=Vocabulary=VT2,Vocabulary__buchong=bc1,Vocabulary=VT1
|fields=VT2._ID=VocID
|where=VT1.book='{{{book}}}' AND VT1.unit={{{unit}}} AND VT2.book='{{{book}}}' AND VT2.unit={{{unit}}} AND VT2.nocohort HOLDS NOT '{{{cohort}}}' AND VT1.wordtype= 'basic' AND VT2.wordtype= 'extra'
|join on=VT2._pageName=bc1._value,bc1._rowID=VT1._ID
|format=template
|template=ArrayDefine
|default=
|delimiter=,
|order by= VocID ASC
|named args=Yes
|limit=5000
}}
  • The query can't be done with an error message:
Error 1054: Unknown column 'bc1._pageID' in 'field list'
Function: CargoSQLQuery::run Query: SELECT `VT1`.`_pageID` AS `cargo_backlink_page_id_VT1`,`bc1`.`_pageID` AS `cargo_backlink_page_id_bc1`,`VT2`.`_pageID` AS `cargo_backlink_page_id_VT2`,`VT2`.`_ID` AS `VocID` FROM `sflscargo__Vocabulary` `VT2` LEFT OUTER JOIN `sflscargo__Vocabulary__buchong` `bc1` ON ((`VT2`.`_pageName`=`bc1`.`_value`)) LEFT OUTER JOIN `sflscargo__Vocabulary` `VT1` ON ((`bc1`.`_rowID`=`VT1`.`_ID`)) WHERE `VT1`.`book`='3' AND `VT1`.`unit`=1 AND `VT2`.`book`='3' AND `VT2`.`unit`=1 AND `VT2`.`_ID` NOT IN (SELECT `_rowID` FROM `sflscargo__Vocabulary__nocohort` WHERE `_value`= '{{{cohort}}}') AND `VT1`.`wordtype`= 'basic' AND `VT2`.`wordtype`= 'extra' ORDER BY `VocID` LIMIT 5000

This could be temporarily avoided if I ignore the backlink function:

$wgCargoIgnoreBacklinks = true;

Then I will receive the correct table _ID number that I would put into other use:

1464,1465,1582,1584,2208,2209,2210,2310,2311,2330

**Currently I use the latest Cargo master branch 3.5, but this began from version 3.4.3 when backlink function appearred.

Event Timeline

I review the code in CargoQuery.php, finding that there's a ignore condition based on the double underscore:

// Ignore helper tables.
					if ( strpos( $table, '__' ) !== false ) {
						continue;

So I try to add dboule underscore to the table alias too, from bc1 to bc__1. The problem seems go away. Maybe the future fix could be better if it checks the original table name before the alias is added.

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

[mediawiki/extensions/PageForms@master] Fix helper table checking for backlinks querying

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

Change 1010207 abandoned by Yaron Koren:

[mediawiki/extensions/PageForms@master] Fix helper table checking for backlinks querying

Reason:

Wrong extension

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

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

[mediawiki/extensions/Cargo@master] Fix helper table checking for backlinks querying

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

Change 1010208 merged by jenkins-bot:

[mediawiki/extensions/Cargo@master] Fix helper table checking for backlinks querying

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

Yaron_Koren claimed this task.
Yaron_Koren subscribed.

@KloudZ - thanks for diagnosing this problem. I think the patch I checked in fixed the problem; feel free to re-open this if not.