Page MenuHomePhabricator

Pywikibot doesn't provide any convenient way to remove Wikidata aliases
Closed, ResolvedPublic

Description

(Actually, it does but that doesn't work.)

If you want remove a label or description, you can run

item.labels['en'] = ''
item.descriptions['en'] = ''
item.editEntity()

or

item.labels.pop('en')
item.descriptions.pop('en')
item.editEntity()

or

data = {'labels': {'en': ''}, 'descriptions': {'en': ''}}
item.editEntity(data)

However, if you want to remove an alias / aliases, you must provide data with accordance to change-op-serializations.wiki (which isn't really convenient):

data = {'aliases': [{'language': lang, 'value': alias, 'remove': ''} for alias in aliases]}
item.editEntity(data)

If you manipulate with attributes (like in the first two examples), you will get API error modification-failed: Must be at least one character long because Pywikibot fills the changed fields with empty strings (since they are rejected, this is wrong behavior).

Event Timeline

Xqt triaged this task as Medium priority.May 12 2018, 5:57 AM
Vvjjkkii renamed this task from Pywikibot doesn't provide any convenient way to remove Wikidata aliases to 73caaaaaaa.Jul 1 2018, 1:10 AM
Vvjjkkii raised the priority of this task from Medium to High.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from 73caaaaaaa to Pywikibot doesn't provide any convenient way to remove Wikidata aliases.Jul 2 2018, 5:48 AM
CommunityTechBot lowered the priority of this task from High to Medium.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.

Funny thing is that it works fine to remove aliases as long as you leave at least one alias left for the given language. But trying to remove all aliases for a given language will not work:

item.aliases['en'] = []
item.editEntity()

This appears to be an inconsistency in the Wikibase api, so I tried filing T203337.

Btw. the last example (the not really convenient one) also doesn't work now because data['aliases'].items() in the _normalizeData method fails when data['aliases'] is a list. This should be fairly simple to fix though.

Change 460742 had a related patch set uploaded (by Matěj Suchánek; owner: Matěj Suchánek):
[pywikibot/core@master] [IMPR] Fix Wikibase aliases handling

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

Change 460742 merged by jenkins-bot:
[pywikibot/core@master] [IMPR] Fix Wikibase aliases handling

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