Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[maintenance] Wikimedia\Rdbms\Platform\SQLPlatform::isWriteQuery fallback to regex #5568

Open
Seb35 opened this issue Dec 6, 2023 · 1 comment
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error

Comments

@Seb35
Copy link
Contributor

Seb35 commented Dec 6, 2023

Setup

  • SMW version: 4.1.2
  • MW version: 1.40.1
  • PHP version: 7.4 (non-relevant)
  • DB system (MySQL, Blazegraph, etc.) and version: MariaDB 10.5 (non-relevant)

Issue

This is a maintenance task about the warning Wikimedia\Rdbms\Platform\SQLPlatform::isWriteQuery fallback to regex.

This warning is triggered in high volumes since MediaWiki requires the query type (essentially if it is a write or read, but there are subtypes) since 1.40 (this Gerrit change), after these constants were introduced in MediaWiki 1.35 (this commit).

The query types are the constants ISQLPlatform::QUERY_CHANGE_* (see this link):

  • QUERY_CHANGE_NONE (subtype of read) for Data Query Language (SELECT except when there is the option "FOR UPDATE", …)
  • QUERY_CHANGE_TRX (subtype of read) for Transaction Control Language (BEGIN, COMMIT, USE, SET, …) (NB: COMMIT is considered as read as explained here)
  • QUERY_CHANGE_LOCKS (subtype of read) for advisory locks
  • QUERY_CHANGE_ROWS (subtype of write) for Data Manipulation Language (UPDATE, DELETE, LOCK, …)
  • QUERY_CHANGE_SCHEMA (subtype of write) for Data Definition Language (CREATE, DROP, ALTER, …)

To avoid this warning, the calls to Wikimedia\Rdbms\Database::query() must have a third parameter with the query type from the constants above. Obviously, calls to Database::select(), Database::delete() are automatically classified.

Example of stack trace (but there are many different ones):

/mediawiki-1.40.1/includes/libs/rdbms/platform/SQLPlatform.php:1765
/mediawiki-1.40.1/includes/libs/rdbms/database/Database.php:935
/mediawiki-1.40.1/includes/libs/rdbms/database/Database.php:846
/mediawiki-1.40.1/includes/libs/rdbms/database/DBConnRef.php:119
/mediawiki-1.40.1/includes/libs/rdbms/database/DBConnRef.php:306
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/MySQLTableBuilder.php:385
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/MySQLTableBuilder.php:281
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/SQLStore/TableBuilder/TableBuilder.php:169
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/SQLStore/Installer.php:229
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/SQLStore/SQLStore.php:456
/mediawiki-1.40.1/extensions/SemanticMediaWiki/src/Store.php:490
/mediawiki-1.40.1/includes/installer/DatabaseUpdater.php:557
/mediawiki-1.40.1/includes/installer/DatabaseUpdater.php:525
/mediawiki-1.40.1/maintenance/update.php:207
/mediawiki-1.40.1/maintenance/includes/MaintenanceRunner.php:681
/mediawiki-1.40.1/maintenance/doMaintenance.php:100
/mediawiki-1.40.1/maintenance/update.php:320
@Seb35 Seb35 added the bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error label Dec 6, 2023
@Seb35
Copy link
Contributor Author

Seb35 commented Dec 6, 2023

I began to classify some calls to Database::query() I will submit shortly a PR.

Seb35 added a commit to WikiValley/SemanticMediaWiki that referenced this issue Dec 6, 2023
This is a classification of the SQL queries introduced by MediaWiki
1.35 and it becomes heavily-recommended in 1.40 (warnings emitted).

This uses intentionally IDatabase::QUERY_CHANGE_* constants and not
ISQLPlatform::QUERY_CHANGE_* to be compatible with MW 1.35; and the
interface ISQLPlatform is a parent interface of IDatabase from 1.39.

Issue: SemanticMediaWiki#5568
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Occurrence of an unintended or unanticipated behaviour that causes a vulnerability or fatal error
Projects
None yet
Development

No branches or pull requests

2 participants
@Seb35 and others