Skip to content

Fix Claims.add() default to preserve existing claims instead of replacing them - #926

Draft
LeMyst with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-claim-adding-issue
Draft

LeMyst with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-claim-adding-issue

Conversation

Copilot AI commented Nov 10, 2025

Copy link
Copy Markdown
Contributor

Claims.add() defaulted to ActionIfExists.REPLACE_ALL: adding a claim to an entity fetched from the instance marked every existing claim with the same property for removal, so they were deleted on write() (#922).

Changes

  • The default action_if_exists of Claims.add() is now ActionIfExists.APPEND_OR_REPLACE, the same default as BaseEntity.add_claims(): the new claim is appended, and an identical claim is not duplicated.
  • Regression tests in test/test_models.py (TestClaims) and an offline write test in test/test_entity_item.py checking that the wbeditentity payload does not remove the existing claims.
  • README: the "Modify an existing item" example documents the new default and how to get the previous behavior.

⚠️ Behavior change

Scripts relying on item.claims.add(...) replacing the existing claims of the property will now append instead, without any error. To keep the previous behavior, pass the action explicitly:

item.claims.add(claim, action_if_exists=ActionIfExists.REPLACE_ALL)

This should be mentioned in the release notes.

Out of scope

Qualifiers.add(), References.add(), Reference.add(), Senses.add() and write_required() still default to REPLACE_ALL and are left unchanged here.

Fixes #922

🤖 Generated with Claude Code

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
Copilot AI and others added 4 commits September 19, 2026 17:48
Co-authored-by: LeMyst <1592048+LeMyst@users.noreply.github.com>
Co-authored-by: LeMyst <1592048+LeMyst@users.noreply.github.com>
Replace the standalone test file with regression tests in TestClaims and an
offline write test against MockWikibase, and document the new default in the
README "Modify an existing item" example.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@LeMyst
LeMyst force-pushed the copilot/fix-claim-adding-issue branch from 5ed5f5a to 1c143f3 Compare September 19, 2026 15:53

This branch has not been deployed

No deployments
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