Last modified: 2012-11-20 09:32:02 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T44058, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 42058 - Enforce type discipline in Dataitem constructors; fail early on errors
Enforce type discipline in Dataitem constructors; fail early on errors
Status: ASSIGNED
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
master
All All
: Low minor (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-13 04:00 UTC by Yaron Koren
Modified: 2012-11-20 09:32 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Yaron Koren 2012-11-13 04:00:05 UTC
In the code for Semantic Drilldown, there's a set of lines that essentially looks like this:

$store = smwfGetStore();
$page = new SMWDIWikiPage( $pageName, $pageNamespace, null );
$property = new SMWDIProperty( $propertyID );
$requestOptions = null;
return $store->getPropertyValues( $page, $property, $requestOptions );

However, this didn't work for any values that were passed in - and it turned out to be because the SQL query that SMW was using to get the SMW ID of the original page failed; and that was because the "iw" (interwiki) value in the query was null, but in the smw_object_ids table all the empty "iw" values are instead blank strings.

After tracing the cause of the problem, I was able to fix it by adding the following line on line 252 of SMWSql3SmwIds::getSMWPageIDandSort(), right before the database select call:

if ( is_null( $iw ) ) { $iw = ''; }

I could just check in that line, but I wasn't sure that that was the right thing to do - or maybe there's something that needs fixing in my original SD code.
Comment 1 Markus Krötzsch 2012-11-13 20:05:27 UTC
Thanks for digging this up. This should definitely return you an empty string. But normally this should not require a special code line. Will investigate.
Comment 2 Markus Krötzsch 2012-11-19 21:05:31 UTC
I have reconsidered this now. It is correct for getPropertyValues() and any other SMW function to respect this discrepancy. This was not seen in earlier versions of SMW since we were not always using the MW database wrapping functions (building your own WHERE condition can mix up null and empty strings). But MySQL distinguishes NULL and empty strings very clearly, and so should we.

The actual error here is in the code that you sketched above. It calls a method that expects a string with null. SMW should help to discover such errors by throwing an exception when you pass null where a string is needed, but this is only a small change.
Comment 3 Yaron Koren 2012-11-19 21:55:26 UTC
Ah - changing the call from:

new SMWDIWikiPage( $pageName, $pageNamespace, null );

to

new SMWDIWikiPage( $pageName, $pageNamespace, '' );

...did indeed fix the problem. I just checked in that change to the Semantic Drilldown code.

I still think it's weird that calling it with blank instead of null causes it to no longer work. Does it ever make sense to different between a blank and a null value for the interwiki? Throwing an exception would be fine, but so, I think, would having that constructor method change a null value to a blank one.
Comment 4 Yaron Koren 2012-11-19 21:58:09 UTC
I meant "to differentiate", above.
Comment 5 Markus Krötzsch 2012-11-20 09:32:02 UTC
Good to hear that it works now.

Regarding your questions: null and '' (and 0 and false) are different things. We are not making extra effort to differentiate between them. We just don't make any effort to treat them as equal. Due to the way in which PHP works, this can sometimes go unnoticed for some time, since things can easily get type converted if you are not careful.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links