⚓ T318845 Disallow passing raw subqueries to IDatabase::tableName
Page MenuHomePhabricator

Disallow passing raw subqueries to IDatabase::tableName
Closed, ResolvedPublic

Description

This has been instrumented with a warning for a number of years and is generally considered an anti-pattern.

The good news is that this isn't actually a pattern we've had to move away from, it was just never really a thing in recent history.

Despite that, we have seen in two cases in recent years that changes to code accidentally resulted in this indirectly happening and we missed it for a while because it isn't enforced.

We are getting 1.3M/day warnings for bad use of table name in building queries in RC.

It's probably something […] turned on this week but this needs fixing.

This was caused by:

SpecialRecentChangesLinked: Pass query builder instead of SQL

https://gerrit.wikimedia.org/r/c/mediawiki/core/+/825078

And fixed in:

Change 831082 merged by jenkins-bot:

[mediawiki/core@master] rdbms: Allow SubQuery objects in SelectQueryBuilder as table

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

Proposal

Turn the warning into an exception. As suggested by @aaron:

Can this warning become an exception now (or the check removed completely)?

Event Timeline

Change 1003545 had a related patch set uploaded (by Aaron Schulz; author: Aaron Schulz):

[mediawiki/core@master] rdbms: error out when passing raw subqueries to IDatabase::tableName()

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

Change 1003545 merged by jenkins-bot:

[mediawiki/core@master] rdbms: error out when passing raw subqueries to IDatabase::tableName()

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