Page MenuHomePhabricator

editAliases makes nothing
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

import pywikibot
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
item=pywikibot.ItemPage(repo, "Q38668500")
a={'fr':'NUR 2010','en':'NUR 2010'} #or whatever you want
item.editAliases(aliases=a)

What happens?:
Nothing happens, no error, but also no action on wikidata. It used to work.

What should have happened instead?:
The alias on wikidata should be edited.

Software version (skip for WMF-hosted wikis like Wikipedia):
I updated to 7.6.0

My console is
"Python 3.8.10 (default, Mar 15 2022, 12:22:08)
Type "copyright", "credits" or "license" for more information.

IPython 7.29.0 -- An enhanced Interactive Python."

Other information (browser name/version, screenshots, etc.):
Thanks for the great work. I use pywikibot since years, it definitely helps!

Event Timeline

Xqt triaged this task as High priority.Sep 17 2022, 5:40 PM
Xqt added a subscriber: matej_suchanek.
Xqt changed the task status from Open to In Progress.Sep 18 2022, 7:30 AM
Xqt claimed this task.
Xqt changed the task status from In Progress to Open.Sep 18 2022, 8:18 AM

This task is invalid, refer the documentation:
Aliases should be a dict, with the key as a language or a site object. The value should be a list of strings
https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.page.html#page.WikibasePage.editAliases

Should this task become a feature request to enable single strings?

Xqt raised the priority of this task from High to Needs Triage.Sep 18 2022, 9:41 AM

Change 832739 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] raise TypeError in AliasesDict.normalizeData if data value is not a list

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

A dic instead of a list you mean?
If you look at: https://www.mediawiki.org/wiki/Manual:Pywikibot/Wikidata/fr

'aliases': {'en': ['Douglas Noel Adams', 'another alias'], 'de': ['Douglas Noel Adams']}

Maybe your mean that within the dic, it should be a list (which I am sure is new). So the example above is ok, but this is not ok:

'aliases': {'en': 'Douglas Noel Adams', 'another alias', 'de': 'Douglas Noel Adams'}

You have used a={'fr':'NUR 2010','en':'NUR 2010'} which is invalid for the current implementation. What I meant is to allow this for a single alias. For multiple aliases a sequence (i.e. a list) has to be used anyway.

Nothing happens, no error, but also no action on wikidata. It used to work.

Errors should never pass silently. So this should be fixed.

Should this task become a feature request to enable single strings?

I am hesitant about this. Note that the method is called editAliases. It is 1) in the plural and 2) it edits them (i.e., replaces them, it does not just add them).
So it is probably useful for maintaining (tidying) data, but not importing data when you just want to add some data, without replacing existing data. (I believe this is the intention behind this, or at least replacing existing aliases with a new single one is not the intention.)

We could introduce a new method like addAliases or so which would just let you add them. This method could also support providing a single string.

Thank you for your valuable comment.

Nothing happens, no error, but also no action on wikidata. It used to work.

Errors should never pass silently. So this should be fixed.

The patch I've added raises TypeError in such case

Should this task become a feature request to enable single strings?

I am hesitant about this. Note that the method is called editAliases. It is 1) in the plural and 2) it edits them (i.e., replaces them, it does not just add them).

I am fine with it to keep the current behaviour except raising the exception if the data type is wrong.

Change 832739 merged by jenkins-bot:

[pywikibot/core@master] [IMPR] raise TypeError in AliasesDict.normalizeData if data value is not a list

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

Sorry, I was on a leave. The documentation says that the "[" "]" are required, so I think it should be fine. No idea why it worked before. Thx for the action.