Skip to content

[fix]: Compulsory DE operands import error#1055

Open
deeonwuli wants to merge 12 commits intodevelopmentfrom
fix/compulsory-de-operands-import-error
Open

[fix]: Compulsory DE operands import error#1055
deeonwuli wants to merge 12 commits intodevelopmentfrom
fix/compulsory-de-operands-import-error

Conversation

@deeonwuli
Copy link
Copy Markdown
Contributor

@deeonwuli deeonwuli commented Mar 13, 2026

📌 References

📝 Implementation

Problem: When dataSets are exported, compulsory data element operands may lack a categoryOptionCombo.id, causing import failures.
Solution: This fix ensures all data element operands in the dataset payload have valid coc id, defaulting to the "default" coc id if not present

📹 Screenshots/Screen capture

📑 Others

#869cemv66

@bundlemon
Copy link
Copy Markdown

bundlemon Bot commented Mar 13, 2026

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
2.75MB (+44B 0%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@deeonwuli deeonwuli changed the title Fix/compulsory de operands import error [fix]: Compulsory DE operands import error Mar 16, 2026
@deeonwuli deeonwuli marked this pull request as ready for review March 16, 2026 15:27
Copy link
Copy Markdown
Contributor

@gqcorneby gqcorneby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[code-only review] Thanks @deeonwuli! Just some minor comments and clarifications :)

const fixedCompulsoryDEOperands = dataSet.compulsoryDataElementOperands.map(operand => {
if (operand.categoryOptionCombo?.id) return operand;

return defaultCategoryOptionCombo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultCategoryOptionCombo will always be truthy at this point because a guard is in place after declaration. The ternary operation can be simplified into a spread directly

Comment thread src/domain/metadata/builders/MetadataPayloadBuilder.ts Outdated
Comment thread src/domain/metadata/builders/MetadataPayloadBuilder.ts Outdated
}

when(mockedMetadataRepository.listAllMetadata(anything())).thenResolve([]);
when(mockedMetadataRepository.getCategoryOptionCombos(anything())).thenResolve([]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a test for when getCategoryOptionCombos returns a real combo, verifying that operands with a missing categoryOptionCombo.id get it replaced with the default one.

@MiquelAdell MiquelAdell removed their request for review March 23, 2026 12:48
@deeonwuli deeonwuli requested a review from gqcorneby April 15, 2026 21:18
Copy link
Copy Markdown
Contributor

@gqcorneby gqcorneby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[code-only review] Thanks @deeonwuli!!

@adrianq adrianq requested a review from xurxodev April 20, 2026 14:16
Copy link
Copy Markdown
Contributor

@xurxodev xurxodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @deeonwuli

I tried test following the steps in the task using the dataset that indicate the task in our WIDP instance but I can't because it's failing a sync using dataset NTD GNARF(NnhyjiUbcJN)

I did a direct url call and the compulsory data element operands is ok.

Image

This PR asume this bug and patch the payload if categoryOptionCombo.id is empty but what is the reason for this situation in the sync?

because a direct api url is ok how you can see in the image and this url: https://dev.eyeseetea.com/who-dev-41/api/dataSets/NnhyjiUbcJN?fields=id,name,compulsoryDataElementOperands

In this moment I have the doubt if it's possible fix the problem without patch the payload but in the previous calls. I don't know if you reviewed this possibility, if it's possible the patch is not necessary and the fix should be done before.

Anyway I can't tests because the sync is failing, can you review it?

Image

@deeonwuli
Copy link
Copy Markdown
Contributor Author

deeonwuli commented Apr 27, 2026

Hi @xurxodev, thanks for the review. You were right that patching the payload was not fixing it at the source.

I found that the root cause was MetadataD2ApiRepository.getMetadata was calling /api/metadata with defaults=EXCLUDE. For datasets, this strips the default categoryOptionCombo.id from every object in compulsoryDataElementOperands.

Fix: Instead of correcting operands during payload construction, the fetch itself now preserves those nested default references:

About the testing blocker (NTD GNARF / 500 error): I raised the issue with Arnau in this ClickUp task. This error has not been further explored and has not come up in any of our other projects yet. So it looks unrelated to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants