Page MenuHomePhabricator

Deprecate and remove DBAccessBase class
Closed, ResolvedPublic

Description

The DBAccessBase class is being deprecated and removed. Instead of extending it, inject a load balancer (factory) and optionally a wiki into the constructor.


Original description:

DBAccessBase is difficult to use with dependency injection

DBAccessBase is a base class for objects that need access to other wiki’s databases. Its constructor calls MediaWikiServices::getInstance()->getDBLoadBalancerFactory(), which means that this class, and any class extending it, is impossible to use in a unit test (where the service wiring is not set up). The lb factory should instead be injected into the constructor (optionally falling back to MediaWikiServices).

An added complication is that, although DBAccessBase is only extended in Wikibase, the class itself is defined in MediaWiki, and marked @stable to extend.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I think we can go even further and just eliminate the class entirely. It provides no value - it has 3 lines of very simple code in it, no other classes seem to have methods typed with "DBConnectionBase" - zero value.

For marking value objects that 'belong to a certain wiki' in cross-wiki environment, we now have WikiAwareEntity interface and a corresponding trait - see UserIdentityValue, PageIdentityValue etc for examples. For fetching a load balancer from a set domain we can just copy-paste that one line of code.

If wikibase repos dependency on this class we can hard-deprecate it.

Yea, it's not good to use a base class for this. It should be a trait, or just be removed.

daniel triaged this task as Low priority.Apr 6 2021, 8:41 PM

Not high prio for the PET team, but if anyone wants to take it on, please do :)

Wikibase no longer uses DBAccessBase, so I assume the class can now be soft-deprecated in core, and then hard-deprecated and eventually removed later.

I’m not sure if we’ll backport all the Wikibase changes to REL1_36, but I assume at least the soft-deprecation can be backported to MediaWiki 1.36 as well?

Change 683819 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] Soft-deprecate DBAccessBase class

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

Change 683819 merged by jenkins-bot:

[mediawiki/core@master] Soft-deprecate DBAccessBase class

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

I assume at least the soft-deprecation can be backported to MediaWiki 1.36 as well?

Apparently not.

In that case I guess we go ahead with hard deprecation immediately.

Change 692264 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] Hard-deprecate DBAccessBase class

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

Lucas_Werkmeister_WMDE renamed this task from DBAccessBase is difficult to use with dependency injection to Deprecate and remove DBAccessBase class.May 17 2021, 1:50 PM
Lucas_Werkmeister_WMDE updated the task description. (Show Details)

Change 692264 merged by jenkins-bot:

[mediawiki/core@master] Hard-deprecate DBAccessBase class

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