Error after upgrading to DHIS2 2.40.5 - "Can not add a Model without id to a ModelCollection

Hi everyone,

After upgrading our DHIS2 instance from 2.38 to 2.40.5, I’m encountering an issue when accessing certain option sets.

When I try to access an option set via the API, I receive the following error:
“Can not add a Model without id to a ModelCollection”

The JSON response shows that some options are null:

{
  "options": [
    null,
    null,
    null,
    {"name": "Gastro-enterologist", "id": "XCztWMFzC8P"},
    {"name": "Internist", "id": "IGvGP4cQ2WF"},
    {"name": "Infectiologist", "id": "lTu8wpea8BK"}
  ]
}

Context:

  • The upgrade was from 2.38 to 2.40.5.
  • These option sets were working correctly before the upgrade.

Questions:

  1. Were there any changes in option set management between these versions?
  2. How can I effectively identify and fix these null options?
  3. Are there any scripts or tools to clean corrupted option sets after a migration?

Thank you in advance for your help!

1 Like

Hello

I noticed something like that on one our instance.
It was due to the sort_order not beginning at 1 or having gaps in the order

not sure it’s fixable through the api/maintenance screen

I had to locate the optionvalue for that optionSet, then figure out the update needed

select * from optionvalue where optionsetid = 121
update optionvalue set sort_order = 1 where optionvalueid = xxx

and finally restart dhis2 or clear the cache in the data administration screen.

see optionSet api return null in the options

2 Likes