Vladis13 created this task.
Vladis13 added a project: Pywikibot.
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper.

TASK DESCRIPTION
  **What happens?**:
  My bot creates items for wikipages, then claims are added to them.
  
  The `WikidataBot.create_item_for_page()` method (`pywikibot/bot.py`) doesn't 
return the ID of the created item, that makes it impossible to add claims to 
it. 
  My bot has been working for several years, there was no such error before.
  
  **Other information**:
  This is the end of this method:
  
    def create_item_for_page(self, page, data=None, summary=None, **kwargs):
        # ....
        result = self.user_edit_entity(item, data, summary=summary, **kwargs)
        if result:
            return item
        return None
  
  Here, when the element is created, `result` becomes `True`. But the element 
ID is not updated and remains equal to `-1`, this erroneous value is returned 
to the calling method. So attempting to add a claim by that id causes a bot 
error.
  
  My calling method:
  
    def treat_page_and_item(self, page, item):
        """Treat page/item."""
        # ...
    
        item = self.create_item_for_page(page, data=data, callback=lambda _, 
exc: self._callback(page, exc))
        if item:
                self.add_claims(item, claims)
  
  I tried to add a dirty hack to the calling method: make 5 attempts, with a 
pause of 2 seconds, request a page element and its ID. But it doesn't help:
  
    def treat_page_and_item(self, page, item):
        """Treat page/item."""
        # ...
    
        item = self.create_item_for_page(page, data=data, callback=lambda _, 
exc: self._callback(page, exc))
        for _ in range(5):
            if item.id == '-1':
                try:
                    time.sleep(2)
                    item = page.data_item()
                except:
                    continue
            else:
                self.add_claims(item, claims)
                break
  
  The bot creates erroneous items without claims. The big problem now is to 
look for them in the bot's contributions to fix them. And I don't know how to 
fix the bot.
  https://www.wikidata.org/w/index.php?title=Q121334607&action=history
  https://www.wikidata.org/w/index.php?title=Q121356015&action=history
  https://www.wikidata.org/w/index.php?title=Q121356016&action=history
  https://www.wikidata.org/w/index.php?title=Q121356017&action=history
  https://www.wikidata.org/w/index.php?title=Q121356018&action=history
  https://www.wikidata.org/w/index.php?title=Q121356019&action=history
  
  My bot page: 
https://github.com/vladiscripts/ws_create_items_for_enc/blob/master/create_items_bot.py

TASK DETAIL
  https://phabricator.wikimedia.org/T344086

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Vladis13
Cc: Aklapper, pywikibot-bugs-list, Vladis13, PotsdamLamb, Jyoo1011, 
JohnsonLee01, SHEKH, Dijkstra, Khutuck, Zkhalido, Viztor, Wenyi, Tbscho, MayS, 
Mdupont, JJMC89, Dvorapa, Altostratus, Avicennasis, mys_721tx, Xqt, jayvdb, 
Masti, Alchimista
_______________________________________________
pywikibot-bugs mailing list -- pywikibot-bugs@lists.wikimedia.org
To unsubscribe send an email to pywikibot-bugs-le...@lists.wikimedia.org

Reply via email to