pycountry icon indicating copy to clipboard operation
pycountry copied to clipboard

Country code in subdivision code breaks references between entries

Open JuroOravec opened this issue 5 years ago • 1 comments

When a subdivision code already includes country code, and this subdivision is parent to another subdivision, the child stores the parent code as "{country_code}-{parent_code_with_country_code}", which leads to the reference being "{country_code}-{country_code}-{actual_parent_code}". However, such reference is nonsense and the parent subdivision cannot be obtained through it.

More info in #16.

A workaround/future-proofing against such behavior can be found in this branch. Would it be good for PR?

JuroOravec avatar Jan 20 '20 21:01 JuroOravec

This should not have been an issue for a long time already and is covered by a unit test.

What's the specific example where this doesn't work?

ctheune avatar Jul 02 '20 11:07 ctheune

Code to reproduce:

>>> [(i.code, i.parent_code) for i in pycountry.subdivisions if i.parent_code and not i.parent][:5]
[('GB-ABC', 'GB-GB-NIR'), ('GB-ABD', 'GB-GB-SCT'), ('GB-ABE', 'GB-GB-SCT'), ('GB-AGB', 'GB-GB-SCT'), ('GB-AGY', 'GB-GB-WLS')]

>>> sub = pycountry.subdivisions.get(code='GB-ABC')

>>> print(sub)
SubdivisionHierarchy(code='GB-ABC', country_code='GB', name='Armagh City, Banbridge and Craigavon', parent='GB-NIR', parent_code='GB-GB-NIR', type='District')

nschimmoller avatar Dec 13 '23 13:12 nschimmoller