Skip to content

Complete the bare entity IDs of the values when they're serialized - #1228

Merged
LeMyst merged 4 commits into
masterfrom
lazy-iris
Nov 15, 2026
Merged

LeMyst merged 4 commits into
masterfrom
lazy-iris

Conversation

@LeMyst

@LeMyst LeMyst commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1193 together with #1227 (merged). This is part 2: the datatype IRIs, as you chose. It was updated after checking how Wikibase validates calendar models and globes.

What Wikibase accepts (REL1_45, repo/includes/ValidatorBuilders.php)

Value Required prefix
Time calendarmodel $wikidataBaseUri = 'http://www.wikidata.org/entity/', hardcoded, on every instance
GlobeCoordinate globe the same hardcoded Wikidata prefix
Quantity unit the concept base URI of the local items (ItemVocabularyBaseUri), or "1"

A value with any other prefix is rejected with bad-prefix (EntityUriValidator). The source comment calls it a TODO: "use a configurable vocabulary for calendars and reference globes, instead of hardcoding wikidata".

Behavior

Units follow the instance: Quantity(unit='Q11573') without wikibase_url keeps the bare ID in the datavalue. Snak.get_json() completes it with:

  1. the WIKIBASE_URL of the WikibaseIntegrator instance of the entity, when an entity serializes itself (get_json(), write(), the forms and senses of a lexeme, write_form() / edit_form() / write_sense() / edit_sense());
  2. otherwise wbi_config['WIKIBASE_URL'], read when serialized.

With wikibase_url=, the IRI is built at once, as before.

Calendar models and globes are Wikidata items: Time(calendarmodel='Q1985786') and GlobeCoordinate(globe='Q2') get http://www.wikidata.org/entity/… at once, whatever the instance. Before, they were completed with wbi_config['WIKIBASE_URL'], which Wikibase rejects on any instance other than Wikidata.

  • On another instance, globe='Q2' is now the Earth, with its latitude and longitude ranges.
  • The wikibase_url argument of Time and GlobeCoordinate, and of their set_value(), is ignored and emits a DeprecationWarning. It's removed in 1.0, and I'll add it to Remove the deprecated APIs in 1.0 #1192 after the merge. format2wbi() no longer passes it.
before now
Quantity(unit='Q11573') written through world.item IRI of wbi_config (wrong instance) IRI of world.config['WIKIBASE_URL']
Quantity(unit='Q11573').mainsnak.datavalue['value']['unit'] full IRI 'Q11573' (breaking)
Time(calendarmodel='Q1985786') on a custom instance http://custom/entity/Q1985786, rejected http://www.wikidata.org/entity/Q1985786
GlobeCoordinate(globe='Q2') on a custom instance http://custom/entity/Q2, rejected http://www.wikidata.org/entity/Q2

How

  • Context variable: a private one (models/snak.py), set by the entities around the serialization of their claims, forms and senses. This is instead of adding a wikibase_url argument to around 15 get_json() methods, which would all be frozen in 1.0. It's thread- and async-safe.
  • Equality: _same_datavalue() treats a bare unit as equal to the IRI of that entity on any instance. Snak and Claim use it. So Claims.add() doesn't duplicate a claim read from the instance. Two full IRIs are still compared exactly.
  • Copies keep the bare unit: a claim added as a qualifier, a reference or a reference snak is now copied without resolving its value. These copies used to go through get_json().
  • Fast run: write_required(), get_entities() and load_statements() work on copies of the claims, resolved with the container's Wikibase URL. Claims without a bare unit aren't copied.

Docs

upgrading.md has two breaking-change entries (the units, and the calendar models and globes) and one deprecation entry (wikibase_url of Time / GlobeCoordinate). installation.md describes both rules.

Tests

  • test/test_entity_iris.py, 35 tests:
    • units: kept, resolved when serialized, follow wbi_config, and built at once with wikibase_url;
    • calendar models and globes: a Wikidata IRI on every instance, inside entities of another instance, with bare defaults in wbi_config, and with the Earth ranges;
    • the deprecation, with its warning pointing at the caller, and format2wbi() not warning;
    • entities of another instance (claims, qualifiers, references, lexeme forms and senses), write and read back, the copies, equality, and fast run on another instance.
  • Updated: test_calendar_model_id now expects the Wikidata IRI, and the Mars fast run test has the Wikidata globe IRI in its WKT literal.
  • Integration: test_instance_configuration writes a quantity with a bare unit, Time(calendarmodel='Q1985786') and GlobeCoordinate(globe='Q2') while wbi_config points elsewhere. It reads back the instance's IRI for the unit and the Wikidata IRIs for the calendar model and the globe.
  • Results:
    • 1606 passed, coverage still 100 %, and the suite also passes with -W error::DeprecationWarning.
    • isort, mypy, pylint (E/W), codespell and flynt pass, and so does the nitpicky docs build.

🤖 Generated with Claude Code

LeMyst and others added 2 commits November 15, 2026 22:44
#1193, as decided on 2026-11-15: WikibaseIntegrator(config=...) takes
the options of wbi_config that differ for this instance, and reads the
others from wbi_config when they're used. wbi.config is read-only.

The entities of an instance use its MEDIAWIKI_API_URL, USER_AGENT and
MAX_REQUEST_SIZE for their requests, its WIKIBASE_URL for
get_entity_url(), its DEFAULT_LEXEME_LANGUAGE for new lexemes, and its
SPARQL_ENDPOINT_URL and WIKIBASE_URL for write_required(). The fast run
containers are told apart by their Wikibase URL and MediaWiki API URL
too, and wbi_fastrun.clear_fastrun_store() empties the store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1193, as decided on 2026-11-15: a Quantity unit, a Time calendar model
or a GlobeCoordinate globe given as a bare ID (unit='Q11573') without
wikibase_url keeps it, and Snak.get_json() completes it with the
WIKIBASE_URL of the instance of the entity serializing itself, else
wbi_config's. The entity sets it in a context variable while it
serializes its claims, and the forms and senses of a lexeme.

A bare ID equals the IRI of this entity, so Claims.add() still finds
the claims read from the instance. The claims copied into qualifiers or
references keep it, and fast run completes it with the Wikibase URL of
its container, on copies of the claims.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeMyst LeMyst added this to the v1.0 milestone Nov 15, 2026
@LeMyst LeMyst added the breaking change Not backward compatible, needs a release note label Nov 15, 2026
@LeMyst
LeMyst changed the base branch from instance-config to master November 15, 2026 22:28
LeMyst and others added 2 commits November 15, 2026 23:28
# Conflicts:
#	docs/source/guide/installation.md
#	test/integration/test_wikibase_fastrun.py
#	wikibaseintegrator/entities/lexeme.py
Wikibase only accepts the calendar models of the times and the globes
of the coordinates of Wikidata, whatever the instance: their IRIs must
start with http://www.wikidata.org/entity/ (the hardcoded
$wikidataBaseUri of ValidatorBuilders, REL1_45), other prefixes are
rejected with bad-prefix. Only the units use the concept base URI of
the instance.

So Time and GlobeCoordinate complete a bare ID with the Wikidata prefix
at once, and only the units of Quantity are completed when serialized.
The wikibase_url argument of Time and GlobeCoordinate is ignored and
deprecated, to remove in 1.0. format2wbi() no longer passes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeMyst
LeMyst merged commit 1fcbf7b into master Nov 15, 2026
21 checks passed
@LeMyst
LeMyst deleted the lazy-iris branch November 15, 2026 23:04
This was referenced Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Not backward compatible, needs a release note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-instance configuration: use several Wikibase instances in one process

1 participant