jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] Fix duplicate source detection in user_add_claim_unless_exists

The source argument is a site, but it was mistakenly treated
as a claim object.

Change-Id: I143dba7f5fe21454dc6722281b0efe8f70d5355a
---
M pywikibot/bot.py
1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index f42f5b7..6ca5c61 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -2217,6 +2217,9 @@
:keyword ignore_save_related_errors: if True, errors related to
page save will be reported and ignored (default: False)
:return: whether the item was saved successfully
+
+ .. note:: calling this method with the 'source' argument modifies
+ the provided claim object in place
"""
self.current_page = item

@@ -2262,10 +2265,21 @@
:param exists_arg: pattern for merging existing claims with new ones
:param logger_callback: function logging the output of the method
:return: whether the claim could be added
+
+ .. note:: calling this method with the 'source' argument modifies
+ the provided claim object in place
"""
+ # This code is somewhat duplicate to user_add_claim but
+ # unfortunately we need the source claim here, too.
+ if source:
+ sourceclaim = self.getSource(source)
+ else:
+ sourceclaim = None
+
# Existing claims on page of same property
claims = item.get().get('claims')
assert claims is not None
+
for existing in claims.get(claim.getID(), []):
# If claim with same property already exists...
if 'p' not in exists_arg:
@@ -2296,17 +2310,20 @@
log("Append 'q' to -exists argument to override this behavior")
break

- if ('s' not in exists_arg or not source) and not existing.sources:
+ if ('s' not in exists_arg or not sourceclaim) \
+ and not existing.sources:
logger_callback(
'Skipping {} because claim without source already exists'
- .format(claim.getID(),))
+ .format(claim.getID()))
log("Append 's' to -exists argument to override this behavior")
break

- if ('s' not in exists_arg and source
- and any(source.getID() in ref
- and all(snak.target_equals(source.getTarget())
- for snak in ref[source.getID()])
+ # FIXME: the user may provide a better source, but we only
+ # assume it's the default one
+ if ('s' not in exists_arg and sourceclaim
+ and any(sourceclaim.getID() in ref
+ and all(snak.target_equals(sourceclaim.getTarget())
+ for snak in ref[sourceclaim.getID()])
for ref in existing.sources)):
logger_callback(
'Skipping {} because claim with the same source already '

To view, visit change 814797. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I143dba7f5fe21454dc6722281b0efe8f70d5355a
Gerrit-Change-Number: 814797
Gerrit-PatchSet: 2
Gerrit-Owner: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: JAn Dudík <jan.dudik@gmail.com>
Gerrit-MessageType: merged