Trytond_import_countries fails to update subdivisions

When entering parties using the Tryton client, the Country or Subdivision I enter does not get saved. I assume this is because I need to import countries and subdivisions using trytond_import_countries, and then pick from the list in the Tryton client.

I ran trytond_import_countries, it updated countries but then failed updating subdivisions. I believe this is a known error with issue report https://bugs.tryton.org/issue11128.

If I understand the issue report correctly, the workaround is to edit pycountry/databases/iso3166-2.json and add a new subdivision type:

{
  "code": "BA-BRC",
  "name": "Brčko distrikt",
  "type": "District with special status"
},

but when I examine iso3166-2.json (pycountry 22.3.5), this entry already exists!

Can anyone point out the obvious? What am I missing?

Thanks,
Dale

trytond_import_countries fails:

(env) [tryton@starlord ~/trytond]$  trytond_import_countries -c trytond.conf -d scc
Update countries
Update subdivisions
Traceback (most recent call last):
  File "/usr/home/tryton/trytond/env/bin/trytond_import_countries", line 8, in <module>
    sys.exit(run())
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/modules/country/scripts/import_countries.py"
, line 178, in run
    main(args.database, args.config_file)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/modules/country/scripts/import_countries.py"
, line 158, in main
    do_import()
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/modules/country/scripts/import_countries.py", line 166, in do_import
    subdivisions = update_subdivisions(countries, subdivisions)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/modules/country/scripts/import_countries.py", line 111, in update_subdivisions
    Subdivision.save(records)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/proteus/__init__.py", line 104, in newfunc
    return self.func(owner, *args, **kwargs)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/proteus/__init__.py", line 847, in save
    ids = proxy.create(values, context)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/proteus/config.py", line 203, in __call__
    result = rpc.result(meth(*args, **kwargs))
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/modules/country/country.py", line 240, in create
    return super(Subdivision, cls).create(vlist)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/model/modelsql.py", line 159, in wrapper
    return func(cls, *args, **kwargs)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/model/modelsql.py", line 695, in create
    cls._validate(sub_records)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/model/modelstorage.py", line 90, in wrapper
    return func(*args, **kwargs)
  File "/usr/home/tryton/trytond/env/lib/python3.8/site-packages/trytond/model/modelstorage.py", line 1411, in _validate
    raise SelectionValidationError(gettext(
trytond.model.modelstorage.SelectionValidationError: The value "district with special status" for field "Type" in "Subdivision" is not one of the allowed options. -
(env) [tryton@starlord ~/trytond]$

pycountry version:

(env) [tryton@starlord ~/trytond/env/lib/python3.8/site-packages/pycountry/databases]$ pip list | grep pycountry
pycountry                     22.3.5
(env) [tryton@starlord ~/trytond/env/lib/python3.8/site-packages/pycountry/databases]$

As the bug report says, you must not use pycountry above 20.7.3 (you will be able to update when upgrading to the future series 6.4).

1 Like

Thanks for clarification. I see now the example in the issue was of the breaking code, not the workaround. All fixed. :slight_smile:

(env) [tryton@starlord ~/trytond]$ pip uninstall pycountry
...
(env) [tryton@starlord ~/trytond]$ pip install "pycountry==20.7.3"
...
(env) [tryton@starlord ~/trytond]$ trytond_import_countries -c trytond.conf -d scc
Update countries
Update subdivisions
Update subdivisions parent
Update subdivisions en
(env) [tryton@starlord ~/trytond]$

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.