Currently, editing structured on commons labels using MediaInfo.editEntity() throws errors in various places. Also, the function Mediainfo.editLabels() needs to be added. The current workaround for these is to use Site.editEntity().
The underlying reason for the bug is that the current Pywikibot SDC code in pywikibot/page/_wikibase.py sets Mediainfo.id = -1 until it is loaded with Mediainfo.get(). In Wikidata code, the id is already set when Mediainfo is initialized.
Additional target to fixing editLabels is to add addClaim and removeClaim functions as they start to working at same when the editLabels works.
Relevant files
FilePage.data_item()
MediaItem
The target for the ticket is to get this working.
MediaInfo.editLabels
site = pywikibot.Site('commons', 'commons') site.login() page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif') item = page.data_item() item.editLabels({'en': 'this is test label'})
MediaInfo.addClaim
wikidata_site = pywikibot.Site('wikidata', 'wikidata') site = pywikibot.Site('commons', 'commons') site.login() page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif') item = page.data_item() property_id="P9478" value_id="museovirasto.C397A9B678302675D32592E51E39A2BA" new_claim = pywikibot.Claim(wikidata_site, property_id) new_claim.setTarget(value_id) ret=item.addClaim(new_claim)
MediaInfo.removeClaims
site = pywikibot.Site('commons', 'commons') site.login() page = pywikibot.FilePage(site,'File:Kauppaneuvos Holger Sweins.tif') item = page.data_item() for claim in item.claims[property_id]: item.removeClaims(claim) break