Upgrading#
Breaking changes in v0.14#
v0.14 changes some behaviors of v0.13 that your code may rely on:
The MediaWiki API calls retry by cause (
mediawiki_api_call()andmediawiki_api_call_helper()):A failure (connection error, HTTP 5xx, read timeout of a read-only action) is tried at most
wbi_config['BACKOFF_MAX_TRIES']times (5 by default), waiting 1, 2, 4… seconds, instead of up to 100 times every 60 seconds. An unreachable instance now fails after about 15 seconds instead of about 100 minutes. A read timeout of a write is never retried, as the edit may have been saved.The instance asking to slow down (maxlag, rate limiting, HTTP 429, read-only mode) is still waited for, with the delay it gives, but
max_retriesdefaults to 20 instead of 100. HTTP 429 used to be raised at once.Once the tries are exhausted,
MaxRetriesReachedExceptionis raised as before, chained to the last error.
backoffis no longer a dependency:wbi_backoffimplements the retries of the SPARQL queries and of the logins itself, with the sameBACKOFF_MAX_TRIESandBACKOFF_MAX_VALUEsettings. Installbackoffyourself if your own code imports it.wbi_backoff()no longer accepts the keyword arguments ofbackoff.on_exception(). Client errors (HTTP 4xx) other than 408 and 429 are no longer retried, and a login is triedBACKOFF_MAX_TRIEStimes in all (it was up toBACKOFF_MAX_TRIESsquared CSRF token requests).Some values compared through SPARQL changed:
Property.PTYPEishttp://wikiba.se/ontology#WikibaseProperty(it was#Property, which never matched), andget_sparql_value()ofCommonsMedia,GeoShapeandTabularDatareturns the full Wikimedia Commons IRI of the value (e.g.<http://commons.wikimedia.org/data/main/Data:Paris.map>instead of<Data:Paris.map>).
If you want to stay on v0.13.x, you can put this line in your requirements.txt:
wikibaseintegrator~=0.13.0
Breaking changes in v0.13#
v0.13 contains changes that are not backward compatible with v0.12:
Python 3.11 or newer is required. Python 3.9 and 3.10 are no longer supported.
The fast run mode has been rewritten (see Examples (in “fast run” mode)). Code using
wbi_fastrundirectly needs to be updated:FastRunContainer.get_items()is renamedget_entities().FastRunContainer()takesbase_filteras its first, mandatory argument andbase_data_typeis now optional.use_refsis renameduse_references, anduse_qualifiers(defaultTrue),use_rankandcacheare added.FastRunContainer.write_required()dropscqidand gainsentity_filterandproperty_filter.BaseEntity.write_required()now requiresbase_filter.Data types compared through SPARQL implement
from_sparql_value(), which replacesparse_sparql_value()for the fast run mode.
FormandSensecompare and hash by content (representations or glosses, grammatical features, claims) instead of by identity, and ignore their id. Two distinct objects holding the same content are now equal, and a Form/Sense modified after being added to asetor used as adictkey can no longer be found there.Claims.add()appends by default: itsaction_if_existsdefault is nowActionIfExists.APPEND_OR_REPLACEinstead ofREPLACE_ALL, likeBaseEntity.add_claims(). Adding a claim no longer removes the existing claims with the same property. Passaction_if_exists=ActionIfExists.REPLACE_ALLto keep the previous behavior. Re-adding an existing value now keeps its rank and references, unless the new claim sets them.HTTP requests have a default timeout of 5 seconds to connect and 300 seconds to read. Change it with
wbi_config['TIMEOUT'], or set it toNoneto wait forever as before.Fewer retries by default:
max_retriesdefaults to 100 instead of 1000 inmediawiki_api_call_helper().execute_sparql_query()retries throughwbi_backoff: itsmax_retriesparameter is ignored (with aDeprecationWarning). Failed queries are retried up towbi_config['BACKOFF_MAX_TRIES']times (5 by default), with an exponential wait capped bywbi_config['BACKOFF_MAX_VALUE'], instead of up to 1000 times every 60 seconds. Once the retries are exhausted, the last error is raised (e.g.requests.HTTPError) instead of a bareException. Authentication errors (HTTP 401/403) are not retried.Anonymous edits that are not explicitly allowed raise
AnonymousEditNotAllowedErrorinstead of a bareException.The enums mirroring API values compare equal to them:
WikibaseDatatype,WikibaseRankandWikibaseSnakTypeareStrEnum, andWikibaseTimePrecisionis anIntEnum. A member is now equal to its API value (WikibaseRank.PREFERRED == 'preferred',WikibaseTimePrecision.DAY == 11, both wereFalse), andstr()gives that value ('preferred'instead of'WikibaseRank.PREFERRED'). The JSON sent to the API is unchanged.Empty values are rejected before the write: a claim, qualifier or reference created with
Noneor an empty string as value raisesEmptyValueError(aValueError) listing every empty value, instead of being sent and rejected by the API with anMWApiError. Use theWikibaseSnakType.NO_VALUEorWikibaseSnakType.UNKNOWN_VALUEsnak type to state that there is no value or an unknown value.mwoauthis no longer a dependency: OAuth1 is implemented withoauthlibdirectly. Installmwoauthyourself if your own code imports it.wbi_helpers.default_sessionandwbi_helpers.helpers_sessionare deprecated: requests made without a login now use a private session per thread. The old names still work but emit aDeprecationWarning.
If you want to stay on v0.12.x, you can put this line in your requirements.txt:
wikibaseintegrator~=0.12.15
Breaking changes in v0.12#
A complete rewrite of the WikibaseIntegrator core has been done in v0.12 which has led to some important changes.
It offers a new object-oriented approach, better code readability and support for Property, Lexeme and MediaInfo entities (in addition to Item).
If you want to stay on v0.11.x, you can put this line in your requirements.txt:
wikibaseintegrator~=0.11.3