WMDE-leszek added a comment.

I've had a stab at making constructor parameters related to required properties of Lexeme non-nullable and it seems to break several places where there are explicit new Lexeme() calls.

It seems there are several situations the "empty" lexeme has been created, as discussed below.

Case 1. Diffing

Lexeme/EntityDocument objects are used to calculate diffs between different "phases" of the lexeme. Special cases being 1) lexeme being created, 2) lexeme being destroyed (i.e. deleted). Diffs for those cases are computed by comparing the state N of the lexeme with the "empty" lexeme (i.e. no language, no lemmas etc).

Code pointers:

EntityContent::getDiff -> EntityContent::makeEmptyEntity -> EntityHandler::makeEmptyEntity -> LexemeHandler::makeEmptyEntity

EntityDiffer::getConstructionDiff -> EntityDifferStrategy::getConstructionDiff -> LexemeDiffer::getConstructionDiff
EntityDiffer::getDestructionDiff -> EntityDifferStrategy::getDestructionDiff -> LexemeDiffer::getDestructionDiff

Case 2. Special:NewLexeme page

When submitting the form with the data of the new lexeme filled in, special page class builds up the Lexeme object that is then being saved.

SpecialNewEntity::createForm calls HTMLForm::setSubmitCallback with a function making use of SpecialNewEntity::createEntityFromFormData. That function builds up lexeme "by parts", checking whether some required elements (language, lexical category) fields are filled. This does not seem necessary, as fields are required and being validated to be non-empty earlier on.

Case 3. Getting the Lexeme/EntityDocument object to apply ChangeOps to in the API action code.

wbeditentity API actions allows creating new lexemes with a particular content, and it also allows "clearing" (i.e. removing all existing elements) the lexeme, and filling it with the new data.
It seems for some convenience, the code is dealing with those special behaviour of wbeditentity by allowing to create an empty lexeme object. In other words, there is a code which loads the entity the API action operates on, and in special wbeditentity cases gives back the "empty" lexeme object.

Code pointers:

EntityFactory::newEmpty makes use of 'entity-factory-callback' from WikibaseLexeme.entitytypes.php
EntityFactory::newEmpty is called from
Api\EditEntity::clearEntity (i.e. wbeditentity API called with clear parameter)
and Api\EntitySavingHelper::createEntity (i.e. wbeditentity API called with new=lexeme parameter)

TBC: conclusions from the above findings.


TASK DETAIL
https://phabricator.wikimedia.org/T189185

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: WMDE-leszek
Cc: WMDE-leszek, Pablo-WMDE, Jakob_WMDE, Addshore, Aklapper, Lydia_Pintscher, Lahi, Gq86, Cinemantique, GoranSMilovanovic, QZanden, LawExplorer, Wikidata-bugs, aude, Darkdadaah, Mbch331
_______________________________________________
Wikidata-bugs mailing list
Wikidata-bugs@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to