Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Claims.add() was deleting all existing claims with the same property when adding a new claim, contrary to user expectations. The default behavior was REPLACE_ALL, marking existing claims for removal on write.

Changes

  • Changed default action_if_exists parameter in Claims.add() from REPLACE_ALL to APPEND_OR_REPLACE
  • Added test coverage for the issue scenario and different action_if_exists behaviors

Impact

Before:

item = wbi.item.get('Q105624761')
item.claims.get('P1476')  # Returns 2 existing titles (de, fr)

title_en = MonolingualText(text='English Title', language='en', prop_nr='P1476')
item.claims.add(title_en)
item.write()

# Result: Only English title exists, German and French deleted ❌

After:

item = wbi.item.get('Q105624761')
item.claims.get('P1476')  # Returns 2 existing titles (de, fr)

title_en = MonolingualText(text='English Title', language='en', prop_nr='P1476')
item.claims.add(title_en)
item.write()

# Result: All 3 titles exist (de, fr, en) ✅

Users wanting replace-all behavior can explicitly specify action_if_exists=ActionIfExists.REPLACE_ALL. This aligns Claims.add() with BaseEntity.add_claims(), which already defaulted to APPEND_OR_REPLACE.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpbin.org
    • Triggering command: /home/REDACTED/.cache/pypoetry/virtualenvs/wikibaseintegrator-h1tmzOrO-py3.12/bin/python /home/REDACTED/.cache/pypoetry/virtualenvs/wikibaseintegrator-h1tmzOrO-py3.12/bin/pytest test/test_entity_item.py -v (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Adding claim deletes other claims?</issue_title>
<issue_description>I'm trying to add a Claim to a wikidata item, but instead of adding it and keeping all other claims with same property, the tool deletes all other claims and replaces them.

Specifically,
flametti = wbi.item.get(entity_id='Q105624761')
flametti.claims.get(PROPS['title'])
shows the entity has several claims about regarding title, two of them in German, but none in English (yet) so I'd like to add it:
title_en_string = datatypes.MonolingualText(text='Flametti, or The Dandyism of the Poor', language='en', prop_nr=PROPS['title'])
flametti.claims.add(title_en_string)
If I do flametti.claims.get(PROPS['title']) indeed the local object it has four or so titles, now, as it should.
But after
flametti.write(login=login_instance)
the entity ends up having only one title, the one I just added. Is this expected behaviour? What am I doing wrong?</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 10, 2025 12:40
Co-authored-by: LeMyst <1592048+LeMyst@users.noreply.github.com>
Co-authored-by: LeMyst <1592048+LeMyst@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue where adding claims deletes existing claims Fix Claims.add() default to preserve existing claims instead of replacing them Nov 10, 2025
Copilot AI requested a review from LeMyst November 10, 2025 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding claim deletes other claims?

2 participants