jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/883275 )
Change subject: [Bugfix] Copy snak IDs/hashes when using editEntity
......................................................................
[Bugfix] Copy snak IDs/hashes when using editEntity
Previously, any new claims added manually to the item via direct access
to `item.claims` would keep on getting added again every time editEntity
was called. By assigning the snak IDs/hashes that are created
when a new claim/qualifier/reference is created,
duplicates should not occur.
Note: To allow flake8 to pass, I had to reduce the names of variables.
The original names can be found as a comment on the patchset.
Bug: T327607
Change-Id: I26d043702d7cef63afcfc103ce7206ca9c8e5c41
---
M pywikibot/page/_wikibase.py
M tests/wikibase_edit_tests.py
2 files changed, 75 insertions(+), 0 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 405af2b..ca4e2f1 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -299,8 +299,12 @@
:param data: Data to be saved
"""
+ update_self = False
if data is None:
data = self.toJSON(diffto=getattr(self, '_content', None))
+ # We only want to copy the IDs from the updates
+ # if data was not passed in.
+ update_self = True
else:
data = self._normalizeData(data)
@@ -321,6 +325,27 @@
if hasattr(self, '_content'):
del self._content
self.latest_revision_id = updates['entity'].get('lastrevid')
+ if update_self and 'claims' in updates['entity']:
+ updated_claims = updates['entity']['claims']
+ for claim_prop_id, statements in updated_claims.items():
+ for claim_index, statement in enumerate(statements):
+ claim = self.claims[claim_prop_id][claim_index]
+ claim.snak = statement['id']
+ claim.on_item = self
+ updated_qualifiers = statement.get('qualifiers', {})
+ for qual_propid, qualifier in updated_qualifiers.items():
+ for qual_index, qual_statement in enumerate(qualifier):
+ target_qual_prop = claim.qualifiers[qual_propid]
+ target_qual = target_qual_prop[qual_index]
+ target_qual.hash = qual_statement['hash']
+ updated_references = statement.get('references', [])
+ for ref_grp_idx, ref_grp in enumerate(updated_references):
+ for ref_propid, reference in ref_grp['snaks'].items():
+ for ref_index, ref_stat in enumerate(reference):
+ target_ref_grp = claim.references[ref_grp_idx]
+ target_ref_prop = target_ref_grp[ref_propid]
+ target_ref = target_ref_prop[ref_index]
+ target_ref.hash = ref_stat['hash']
def concept_uri(self) -> str:
"""
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index 0de943f..c0892cf 100755
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -127,6 +127,37 @@
item = pywikibot.ItemPage(testsite)
item.editEntity(data)
+ def test_edit_entity_propogation(self):
+ """Test that ``ItemPage.editEntity`` propagates changes to claims."""
+ testsite = self.get_repo()
+ item = pywikibot.ItemPage(testsite)
+ claim = pywikibot.Claim(testsite, 'P97339')
+ claim.setTarget('test')
+ qual = pywikibot.Claim(testsite, 'P97339')
+ qual.setTarget('test')
+ ref = pywikibot.Claim(testsite, 'P97339')
+ ref.setTarget('test')
+ claim.addQualifier(qual)
+ claim.addSource(ref)
+ item.editEntity()
+ self.assertIsNotNone(claim.snak)
+ self.assertIsNotNone(qual.hash)
+ self.assertIsNotNone(ref.hash)
+ self.assertSame(claim.on_item, item)
+ self.assertSame(qual.on_item, item)
+ self.assertSame(ref.on_item, item)
+ qual = pywikibot.Claim(testsite, 'P97339')
+ qual.setTarget('test')
+ ref = pywikibot.Claim(testsite, 'P97339')
+ ref.setTarget('test')
+ claim.qualifiers[qual.id].append(qual)
+ claim.sources[0][ref.id].append(ref)
+ item.editEntity()
+ self.assertIsNotNone(qual.hash)
+ self.assertIsNotNone(ref.hash)
+ self.assertSame(qual.on_item, item)
+ self.assertSame(ref.on_item, item)
+
def test_edit_entity_new_property(self):
"""Test creating a new property using ``PropertyPage.editEntity``."""
testsite = self.get_repo()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/883275
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I26d043702d7cef63afcfc103ce7206ca9c8e5c41
Gerrit-Change-Number: 883275
Gerrit-PatchSet: 3
Gerrit-Owner: RPI2026F1 <sarkaraoyan+rpi2026f1(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/886411 )
Change subject: [feat] clean_sandbox: Configure script for some projects
......................................................................
[feat] clean_sandbox: Configure script for some projects
Configuration comes from what those projects currently use in their Sandoxes.
Change-Id: Ib0fa7dd47e030d232e7f0d4977676de4f2e852ce
---
M scripts/clean_sandbox.py
1 file changed, 39 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py
index 286a477..b0a97b9 100755
--- a/scripts/clean_sandbox.py
+++ b/scripts/clean_sandbox.py
@@ -23,7 +23,7 @@
-textfile As an alternative to -text, you can use this to provide
a file containing the text to be used.
- -summary Summary of the edit made by bot. Overrides the default
+ -summary Summary of the edit made by the bot. Overrides the default
from i18n.
This script is a :py:obj:`ConfigParserBot <bot.ConfigParserBot>`.
@@ -61,19 +61,40 @@
'commons': '{{Sandbox}}\n<!-- Please edit only below this line. -->',
'meta': '{{Meta:Sandbox/Please do not edit this line}}\n'
'<!-- Please edit below this line. -->',
+ 'species': '{{Sandbox}}\n'
+ '<!-- PLEASE ADD YOUR EDITS BELOW THIS LINE. THANK YOU. -->',
'test': '<noinclude>{{Sandbox}}</noinclude>\n'
'== Please start your testing below this line ==',
'wikidata': '{{Please leave this line alone (sandbox heading)}}',
'wikibooks': {
+ 'es': '{{subst:ZDP/2}}',
'ru': '{{/Шапка}}\n'
'<!-- Не удаляйте, пожалуйста, эту строку, '
'тестируйте ниже -->',
},
- 'wikivoyage': {
+ 'wikinews': {
+ 'es': '{{ZDP}}\n== Haz tus pruebas bajo esta sección ==',
+ },
+ 'wikiquote': {
+ 'es': '{{ZDP}}\n== Haz tus pruebas bajo esta sección ==',
+ },
+ 'wikisource': {
'es': '<!--No borres este mensaje-->'
'{{Zona de pruebas}}'
- '<!--Haz las pruebas debajo. Gracias-->\n\n'
- '== Las pruebas en esta sección ==\n',
+ '<!--Haz las pruebas debajo. Gracias-->\n',
+ },
+ 'wikiversity': {
+ 'es': '{{/encabezado}}\n'
+ '== Haz tus pruebas bajo esta sección ==',
+ },
+ 'wikivoyage': {
+ 'es': '<!--No borres este mensaje-->{{Zona de pruebas}}'
+ '<!--Haz las pruebas debajo. Gracias-->\n'
+ '== Haz tus pruebas bajo esta sección ==',
+ },
+ 'wiktionary': {
+ 'es': '<!--No borres este mensaje-->{{Titular-zdp}}'
+ '<!--Haz las pruebas debajo. Gracias-->',
},
'als': '{{subst:/Vorlage}}',
'ar': '{{عنوان الملعب}}\n<!-- مرحبا! خذ راحتك في تجربة مهارتك في التنسيق '
@@ -104,6 +125,9 @@
'and editing skills below this line. As this page is for editing '
'experiments, this page will automatically be cleaned every 12 '
'hours. -->',
+ 'es': '<!--No borres este mensaje-->{{Titular-zdp}}'
+ '<!--Haz las pruebas debajo. Gracias-->\n'
+ '== Las pruebas en esta sección ==\n',
'eo': '{{Bonvolu ne forigi tiun ĉi linion (Provejo)}}',
'fa': '{{subst:Wikipedia:ربات/sandbox}}',
'fi': '{{subst:Hiekka}}',
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/886411
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0fa7dd47e030d232e7f0d4977676de4f2e852ce
Gerrit-Change-Number: 886411
Gerrit-PatchSet: 4
Gerrit-Owner: MarcoAurelio <maurelio(a)toolforge.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged