Page MenuHomePhabricator

Lua error: "The ID entered is unknown to the system. Please use a valid entity ID." with valid q-code
Closed, ResolvedPublic

Description

Lately I completed T89597 and rolled out on Commons [[Module:Creator]] that mimics [[Template:Creator]] but can also fetch any field from Wikidata if needed. The module is used by 28k creator templates on 1.6M pages. The issue I have is that out of 28k creator templates 12 show "The ID entered is unknown to the system. Please use a valid entity ID" error without any additional explanation. According to T143970, the error message is due to bad q-code, but all of the pages have valid q-codes. Strangely most

My request is to provide more usable information when throwing this error, like which q-code is not valid and in which line was it called. I also would appreciate any hints of how to debug this issue, and what might cause it. See c:User:Jarekt/a for example of the error.

Affected q-codes are: Q2441898, Q558060, Q146691, Q313638, Q19675193, Q113775, Q1394, Q33391, Q559531, Q1988310, Q51088, Q1978510.

Details

Related Gerrit Patches:

Event Timeline

Jarekt created this task.Apr 25 2017, 7:14 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 25 2017, 7:14 PM

Affected q-codes are: Q2441898, Q558060, Q146691, Q313638, Q19675193, Q113775, Q1394, Q33391, Q559531, Q1988310, Q51088, Q1978510.

Whichever id I preview on that page is invalid. {{Authority control}} with the same id works, so there seems to a problem in one of the used modules. Sadly, the error message doesn't provide any stacktrace, so it might be any of them.

Try debuging "Module:Creator" by adding mw.log("'" .. args.wikidata .. "'") just above entity = mw.wikibase.getEntity(args.wikidata) and previewing the test page, you should see what id is actually provided to the function below the edit window.

Is it always mw.wikibase.getEntity that throws this error? That would narrow it down. "args.wikidata" does not change in my code: it is always q-code which was provided. However there might be other calls to getEntity to get labels and links for city names or names of authority control identifiers. That is why stacktrace is essential to debug it.

Unfortunately I never figured out how to use mw.log and lua debbug console and I never found any documentation or examples with it. Even w:Help:Lua_debugging does not mention it.

Is it always mw.wikibase.getEntity that throws this error?

Actually, I didn't think of the other functions. I have just tested them:

console
= mw.wikibase.label( 'foo' )
nil
= mw.wikibase.sitelink( 'foo' )
nil

They just return nil (but I think they should throw errors as well).

Unfortunately I never figured out how to use mw.log and lua debbug console and I never found any documentation or examples with it. Even w:Help:Lua_debugging does not mention it.

Would you change the protection on the module, so that I could debug it? But if the error is beyond it, I might not be able to find the error.

Izno added a subscriber: Izno.EditedApr 26 2017, 3:59 PM

Unfortunately I never figured out how to use mw.log and lua debbug console and I never found any documentation or examples with it. Even w:Help:Lua_debugging does not mention it.

Would you change the protection on the module, so that I could debug it? But if the error is beyond it, I might not be able to find the error.

You can use the sandbox.

I am doing all the testing on Module:Creator/sandbox and Template:Creator/sandbox. Feel free to change them as you wish. I do not think there is a need to change the protection on the live module, especially any vandalism by a 3rd party would result in vandalism of 1.6M pages.

Without greater testing, I think that this piece of code is very unsafe:

data.P27 = Wikidata1.formatStatements({item=entity, property='p27',link='-',conjtype ='/',displayformat='raw'})
if data.P27 then
    args.nationality = Wikidata1.formatStatements({item=data.P27, property='p297',link='-',conjtype ='/'})
end

data.P27 is an arbitrary string which you are assuming to be a Qid.

data.P27 is not arbitrary string but output of Module:Wikidata's formatStatements(...,displayformat='raw'}) which is suppose to return a q-code. That said it might still be unsafe as this code uses functionality of Module:Wikidata which might not have been used much otherwise. When I can I try to use alternatives to Module:Wikidata, which I find too large to easily follow and debug.

Actually, it will return a list of Qids concatenated by '/'. It's just coincidence that it works in most cases.

I think you found the actual issue here. Creator template with "nationality" field bypasses that code and if you provide it the problem does not occur. See User:Jarekt/a. I will fix the module tonight. Thanks matej !

That fixes my specific issue; however my broad issue with no stacktrace info about this bug or any other details useful in debugging is still unsolved.

@hoo is there anything we can do here?

hoo added a comment.May 7 2017, 5:24 PM

@hoo is there anything we can do here?

Yes, we can improve the error reporting so that it's easier to debug problems in user modules.

Change 354258 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/extensions/Wikibase@master] Mention the invalid id in "wikibase-error-invalid-entity-id"

https://gerrit.wikimedia.org/r/354258

Change 354258 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Mention the invalid id in "wikibase-error-invalid-entity-id"

https://gerrit.wikimedia.org/r/354258

After the next Wikidata deploy, you should be able to see what exactly is causing the problems in question so that it should be easier to locate the problem.

Lydia_Pintscher triaged this task as Medium priority.Jun 11 2017, 6:03 PM

The code should be deployed. Can you check and update us here?

hoo closed this task as Resolved.Jun 18 2017, 10:13 AM
hoo claimed this task.

The problem seems no longer reproducible, so I guess the module(s) in question have been fixed.