Page MenuHomePhabricator

Do not call Entity::setId() with an int parameter
Closed, ResolvedPublic

Description

Implementations of Entity::setId() should require an EntityId as a parameter. At present, they also support int parameters, and then create the appropriate EntityId internally. Besides this being a nasty B/C hack, it does not work for foreign IDs.

Support for numeric IDs can be removed from Entity::setId() by making all callers that use an integer construct an EntityId first, using the EntityIdComposer service. In particular, this is the case for WikiPageEntityStore::assignFreshId().

Event Timeline

daniel created this task.Nov 24 2016, 6:19 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 24 2016, 6:19 PM
daniel moved this task from Inbox to To Do on the User-Daniel board.Jan 5 2017, 6:57 PM
daniel moved this task from To Do to Push on the User-Daniel board.
thiemowmde triaged this task as High priority.Mar 13 2017, 6:00 PM
thiemowmde moved this task from incoming to needs discussion or investigation on the Wikidata board.

I triaged this as high because it is quite nasty, extremely old technical debt we want to pay for a long, long time. Luckily it became very easy to finally fix this with what we build in the past months. Just use the existing entity-id-composer-callbacks in WikiPageEntityStore::assignFreshId, and be done. I believe this will be the last instance of numeric calls to setId(). We can remove this feature from all entity types then! (Probably have some kind of deprecation phase for Item and Property.)

I believe this is not a blocker for any of the projects we are currently working on. MediaInfo already works around this issue.

Change 367024 had a related patch set uploaded (by AnotherLadsgroup; owner: Amir Sarabadani):
[mediawiki/extensions/Wikibase@master] Use EntityIdComposer instead of sending numeric id to EntityId::setId()

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

Restricted Application added a subscriber: PokestarFan. · View Herald TranscriptJul 22 2017, 12:20 PM

Change 367024 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Use EntityIdComposer instead of sending numeric id to EntityId::setId()

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

The callers are removed, but the implementation of setId() still accepts integers, and we still have tests using that. @Ladsgroup, can you look into that? This should be fixed for Item, Property, Lexeme, and MediaInfo.

The wikibase-datamodel will need a new release - technically, this is a breaking change, so it should go into the next major release. I don't see a reason to do a major release just for this, though... Do we have a marker for "next release needs to be major"? Having BREAKING in the commit message should do it, i guess...

Already on it, github PR has a tag for breaking we can use that.

Change 367461 had a related patch set uploaded (by AnotherLadsgroup; owner: Amir Sarabadani):
[mediawiki/extensions/WikibaseLexeme@master] Do not let Lexeme::setId accept int as Id

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

Change 367463 had a related patch set uploaded (by Ladsgroup; owner: Amir Sarabadani):
[mediawiki/extensions/WikibaseMediaInfo@master] Do not let MediaInfo::setId accept int as Id

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

Restricted Application added a project: User-Ladsgroup. · View Herald TranscriptJul 24 2017, 8:03 PM

Change 367461 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Do not let Lexeme::setId accept int as Id

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

Change 367463 merged by jenkins-bot:
[mediawiki/extensions/WikibaseMediaInfo@master] Do not let MediaInfo::setId accept int as Id

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

I suggest to mark this ticket as done, as soon as we don't use setId(int) in Wikibase* repositories and make release later when we have more changes.

@Aleksey_WMDE I agree, this ticket does not require the data model release. Just the code to be merged in all repos.

Ladsgroup closed this task as Resolved.Jul 27 2017, 1:37 PM
Ladsgroup moved this task from Review to Done on the Wikidata-Former-Sprint-Board board.

Change 378723 had a related patch set uploaded (by Thiemo Mättig (WMDE); owner: Thiemo Mättig (WMDE)):
[mediawiki/extensions/Wikibase@master] Make Wikibase code base compatible with current DataModel master

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

Change 378723 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Make Wikibase code base compatible with current DataModel master

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