Page MenuHomePhabricator

primary_only doesn't always return primary coordinates
Closed, ResolvedPublic

Description

>>> dewiki = pywikibot.Site('de', 'wikipedia')
>>> page = pywikibot.Page(dewiki, 'Hitlerbauten')
>>> page.coordinates(primary_only=True)
Coordinate(lat=48.314187, lon=14.273416, entity=http://www.wikidata.org/entity/Q2)

However, there are no primary coordinates (query). The method does:

if primary_only:
  return self._coords[0] if len(self._coords) > 0 else None
else:
  return self._coords

ie. chooses the first instance, which is wrong and can confuse bots and other tools.
Primary coordinates are marked with "primary": "" key in the response.

Event Timeline

Change 571852 had a related patch set uploaded (by JJMC89; owner: JJMC89):
[pywikibot/core@master] [FIX] Correctly choose primary coordinates in BasePage.coordinates()

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

Change 571852 merged by jenkins-bot:
[pywikibot/core@master] [FIX] Correctly choose primary coordinates in BasePage.coordinates()

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

Xqt triaged this task as High priority.
Xqt subscribed.

Reopened due to breaking change, see commit comments.

Change 571984 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Return a single Coordinate with primary_only option

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

Change 571984 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Return a single Coordinate with primary_only option

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

JJMC89 removed a project: Patch-For-Review.