Page MenuHomePhabricator

PostgresUpdater sets watchlist wl_namespace to 0 and is therefore causing duplicated key error
Closed, ResolvedPublicBUG REPORT

Description

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

  • Try upgrading a PostgreSQL-based MediaWiki installation to 1.36.1:
  • php update.php

What happens?:
Update script fails with

Changing column type of 'watchlist.wl_namespace' from 'integer' to 'INT'
Wikimedia\Rdbms\DBQueryError from line 1719 of w/includes/libs/rdbms/database/Database.php
: Error 23505: ERROR:  could not create unique index "wl_user_namespace_title"
DETAIL:  Key (wl_namespace, wl_title, wl_user)=(0, string omitted, number omitted) is duplicated.

Function: PostgresUpdater::changeField
Query: ALTER TABLE watchlist ALTER wl_namespace TYPE INT USING 0

Reason: there is an error in the schema update:

			[ 'changeField', 'watchlist', 'wl_namespace', 'INT', 0 ],

This forces PostgreSQL to set the value of wl_namespace to 0 for every row, which is impossible for an indexed field: there is a unique index,

CREATE UNIQUE INDEX wl_user ON mediawiki.watchlist USING btree (wl_user, wl_namespace, wl_title)

and the watchlist table by design will almost always (if someone used the Watch Page function) have rows with differing wl_namespace values:

MediaWiki works with the assumption that when people watch pages they either watch both the talk page and the normal page, or neither. That means that for each watched page MediaWiki always automatically adds two entries: One for the page and one for its talk page. E.g. when the user watches the Main Page, then there will be two rows in the database table: One for the Main Page in namespace 0 and one for the Main Page in namespace 1 (which is the according talk page). Missing page rows are added by the maintenance script update.php.

What should have happened instead?:
Script should have finished execution without errors.

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:
MediaWiki 1.35.2 → 1.36.1 (basic schema upgrade).

Event Timeline

Aklapper renamed this task from MediaWiki installer: error in PostgreSQL schema upgrade for REL1_36 and beyond to PostgresUpdater sets watchlist wl_namespace to 0 and is therefore causing duplicated key error.Jul 22 2021, 11:39 AM
Aklapper added a subscriber: OkayIguess.

Change

			[ 'changeField', 'watchlist', 'wl_namespace', 'INT', 0 ],

into

			[ 'changeField', 'watchlist', 'wl_namespace', 'INT', '' ],

will fix this Bug.

@Willertr: Thanks for taking a look at the code! You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit which makes it easier to review and provide feedback. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks.

Change 714064 had a related patch set uploaded (by Gerrit Patch Uploader; author: Willertr):

[mediawiki/core@master] mediawiki.core: PostgresUpdater sets watchlist wl_namespace to 0 and is therefore causing duplicated key error

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

Change 743498 had a related patch set uploaded (by Gerrit Patch Uploader; author: Willertr):

[mediawiki/core@master] PostgresUpdater fix for DEFAULT 0 in updates for 1.37

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

Change 744866 had a related patch set uploaded (by Ladsgroup; author: Amir Sarabadani):

[mediawiki/core@master] installer: Fix Postgres mistakes in using changeField method

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

Change 745382 had a related patch set uploaded (by Reedy; author: Amir Sarabadani):

[mediawiki/core@REL1_36] installer: Fix Postgres mistakes in using changeField method

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

Change 744866 merged by jenkins-bot:

[mediawiki/core@master] installer: Fix Postgres mistakes in using changeField method

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

Change 745382 merged by jenkins-bot:

[mediawiki/core@REL1_36] installer: Fix Postgres mistakes in using changeField method

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

Change 745381 merged by jenkins-bot:

[mediawiki/core@REL1_37] installer: Fix Postgres mistakes in using changeField method

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

Change 743498 abandoned by Umherirrender:

[mediawiki/core@master] PostgresUpdater fix for DEFAULT 0 in updates for 1.37

Reason:

Should be fixed already with I34070440a766c21baede849c70f06e6e1dbfd5f7

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

Change 714064 abandoned by Umherirrender:

[mediawiki/core@master] installer: Fix \"duplicated key error\" from wl_namespace io PostgresUpdater

Reason:

Should be fixed with I34070440a766c21baede849c70f06e6e1dbfd5f7

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

Umherirrender assigned this task to Reedy.
Umherirrender removed a project: Patch-For-Review.