Can not add a model without id to a ModelCollection

Hi,

I’m trying to edit an Option set using the maintenance app by selecting the edit option. The option set fails to load but gives me the below error:

“Can not add a model without id to a ModelCollection”

I’m on Version 2.39.1. Any suggestion on how I can sort this out?

1 Like

Hello @Mukaha if you are facing that challenge to the option set, some of the option value in the database has not been linked to the option set id in the table optionvalue

So to solve it, you might need to interact with the back-end database and find those option that has not optionsetid and clean them.

1 Like

Thank you @tuzoengelbert allow me to work on this. I will revert in case I encounter a challenge.

1 Like

Having the same issue. Thank you for your response @tuzoengelbert. Is doing this through the back end the only approach? We were only attempting a change in the name of an option set, not creating anything new. I am on version 2.39.3 and wondering if this was related to a bug.

Hello @MELB Do you still get the challenge on this ?

1 Like

Hi, @tuzoengelbert my problem still exists as I don’t have backend experience. Is there any way to address the challenge? Or do you have a guide on how to access the backend to fix it?

1 Like

we had to implement a fix on the back end to address the issue. I have yet to test again to see if the issue persists. I do not have the details on what the fix was. We work with a consultant. I have not tried changing an option again and hesitant to do so in case this issue persists.

1 Like

Hi @Mukaha

I hope @tuzoengelbert and @MELB will be able to help you out. I have a suggestion if you would like to try it out please.

Using the Import / Export app, export Option Set metadata (as JSON and not compressed), and then when the JSON file has been download. Perform a dry run import:

  1. Metadata Import, upload file and select JSON
  2. Import report mode: “Full - Reports for all objects imported”
  3. Import strategy: “Merge - Import new values and update existing”
  4. Atomic mode: Import
  5. Merge mode: Replace
  • Advanced options:
  1. Flush mode: Object (debugging purposes)
  2. Async: Asynchronous import
  3. Inclusion strategy: Always

Start dry run

Please check the error log? If it’s all working great, please test in a testing instance use delete and then import again.

Thanks!

1 Like

First, I will share you the query to check if there is optionvalue that has not been assigned to optionSet

Go to Maintenance => Others =>SQL view

  1. Create SQL View with type view

Type the query

select * from optionvalue where optionsetid is null;

Then let us know if it brings value

2 Likes

Hi @Gassim, thank you for sharing this option. I have tried it on a test environment and it has worked! Many thanks.

Allow me to try it on the dev instance, but before I try this. What would be the implication to existing data?

1 Like

Hi @Mukaha

Yes, please test on a test instance which has the data as well so that you could check if the data is affected. If the data is affected you will need to export it and then after you fix the metadata issue with the above step, import the data again and see if everything is back to normal.

Sorry I couldn’t think of an easier/better way.

Good luck! (:

1 Like

Hi @Gassim,

I tried the solution on the live instance and I am happy to confirm that the error is now gone, and the existing data wasn’t affected.

Many thanks to you and @tuzoengelbert for your support on this matter.

Best!

1 Like

Looks like the issue has been resolved.
https://dhis2.atlassian.net/browse/DHIS2-15351
Glad you were able to resolve on your end @Mukaha

Hi @Mukaha

Thank you for spending time testing and confirming the solution. So glad that it worked. :slight_smile:

1 Like

Thanks @MELB for sharing this link. It never hurts to have more than one way to solve this issue.

1 Like