Investigate how to intercept constraint check reports
A very useful signal of a wrong link is when the constraint check Wikibase extension raises a warning on a given identifier statement.
See the screenshot for an example:

It would be optimal to programmatically intercept these warnings and skip/delete the identifier during the upload process.
Pointers:
- https://www.wikidata.org/wiki/Help:Property_constraints_portal
- https://www.wikidata.org/wiki/Special:ConstraintReport
- https://www.wikidata.org/wiki/Wikidata:Database_reports/Constraint_violations
The wbcheckconstraints Wikidata API action should be what we need:
https://www.wikidata.org/w/api.php?action=help&modules=wbcheckconstraints
Recent breaking change on this API action: https://lists.wikimedia.org/pipermail/wikidata/2019-April/012910.html
This sounds like the tool we need: https://github.com/wmde/wikidata-constraints-violation-checker
This sounds like the tool we need: https://github.com/wmde/wikidata-constraints-violation-checker
Checked it out. The answer is: no, it just shows counts of constraint violations. We need fine-grained control on specific statements.
We should use the claimid parameter of the wbcheckconstraints API endpoint, instead: it expects a claim GUID, though.
it expects a claim GUID, though.
We can retrieve it in the debug logs of our bot, only when a new claim is created (doesn't apply to references).
We should get the id key of the Wikidata API JSON response. For instance:
2021-08-19 15:27:19,997 [DEBUG] wikidata_bot._add #809 - Added claim: {'mainsnak': {'snaktype': 'value', 'property': 'P5431', 'datatype': 'external-id', 'datavalue': {'value': '33d5bc21', 'type': 'string'}}, 'type': 'statement', 'id': 'Q3779971$3162884b-c804-44b1-9972-eb022001f68e', 'rank': 'normal'}
GUID = Q3779971$3162884b-c804-44b1-9972-eb022001f68e
Finally, call https://www.wikidata.org/w/api.php?action=wbcheckconstraints&claimid=Q3779971$3162884b-c804-44b1-9972-eb022001f68e
Waiting for https://phabricator.wikimedia.org/T289710