When we show a random article in the feed, we request a few random titles and sort by various criteria to show the "best" one.
When the api returns article data it can usually tell us whether a random title is a disambiguation page, such as when we get data for the "enwiki > anona" article:
{ "mobileview": { "pageprops": { "disambiguation": "", "wikibase_item": "Q20996443" }, "sections": [ { "id": 1, "text": "<h2><span class=\"mw-headline\" id=\"See_also\">See also</span><span><a href=\"#/editor/1\" title=\"Edit section: See also\" data-section=\"1\" class=\"mw-ui-icon mw-ui-icon-element mw-ui-icon-edit-enabled edit-page icon-32px\">Edit</a></span></h2>\n<ul>\n<li><a href=\"/wiki/Annona_(disambiguation)\" title=\"Annona (disambiguation)\" class=\"mw-disambig\">Annona (disambiguation)</a></li>\n</ul>\n<table id=\"disambigbox\" class=\"metadata plainlinks dmbox dmbox-disambig\" style=\"\" role=\"presentation\">\n<tr>\n<td class=\"mbox-image\" style=\"padding: 2px 0 2px 0.4em;\"><a href=\"/wiki/File:Disambig_gray.svg\" class=\"image\"><img alt=\"Disambiguation icon\" src=\"//upload.wikimedia.org/wikipedia/en/thumb/5/5f/Disambig_gray.svg/30px-Disambig_gray.svg.png\" width=\"30\" height=\"23\" srcset=\"//upload.wikimedia.org/wikipedia/en/thumb/5/5f/Disambig_gray.svg/45px-Disambig_gray.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/5/5f/Disambig_gray.svg/60px-Disambig_gray.svg.png 2x\" data-file-width=\"220\" data-file-height=\"168\" /></a></td>\n<td class=\"mbox-text\" style=\"padding: 0.25em 0.4em; font-style: italic;\">This <a href=\"/wiki/Help:Disambiguation\" title=\"Help:Disambiguation\">disambiguation</a> page lists articles associated with the title <b>Anona</b>.<br />\n<small>If an <a class=\"external text\" href=\"//en.wikipedia.org/w/index.php?title=Special:WhatLinksHere/Anona&namespace=0\">internal link</a> led you here, you may wish to change the link to point directly to the intended article.</small></td>\n</tr>\n</table>" } ] } }
Note "disambiguation": "" page prop is present in the result above, which is correct.
However, sometimes the api messes up and doesn't include the "disambiguation" key, as is the case with "enwiki > HMS Dauntless":
{ "mobileview": { "pageprops": { "displaytitle": "HMS <i>Dauntless</i>", "defaultsort": "Dauntless, Hms", "wikibase_item": "Q5632089" }, "description": "Wikipedia disambiguation page", "sections": [ { "id": 1, "text": "<h2><span class=\"mw-headline\" id=\"In_popular_culture\">In popular culture</span><span><a href=\"#/editor/1\" title=\"Edit section: In popular culture\" data-section=\"1\" class=\"mw-ui-icon mw-ui-icon-element mw-ui-icon-edit-enabled edit-page icon-32px\">Edit</a></span></h2>\n<ul>\n<li>In the 2003 film <i><a href=\"/wiki/Pirates_of_the_Caribbean:_The_Curse_of_the_Black_Pearl\" title=\"Pirates of the Caribbean: The Curse of the Black Pearl\">Pirates of the Caribbean: The Curse of the Black Pearl</a></i>, the fictional HMS <i>Dauntless</i> appears as the flagship and pride of the <a href=\"/wiki/Royal_Navy\" title=\"Royal Navy\">Royal Navy</a>.</li>\n</ul>" } ] } }
Note "disambiguation": "" page prop is missing in the result above, which is incorrect (at least, if the wiki data description is to be believed) and the cause of the bug.
Best fix: So we need to file an upstream ticket for this.
Work-around: In the mean time we could set "isDisambiguation" to YES if either the server response has the "disambiguation" page props key, or if the wiki data description contains the string "disambiguation page".